The following code is very strange, we look
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
/ / Test memory leaks
NSMutableString * foo = [@ "Julia!" MutableCopy];
[Foo autorelease];
[Foo appendString: @ "I am happy"];
NSLog (@ "% d", [foo retainCount]); / / 1
[Pool release];
NSLog (@ "% d", [foo retainCount]); / / -1
I put on the release of foo objects inside the pool, then the pool after the release, it becomes -1, then why? ? ?
From 1 to -1, explain.
Reply:
Their top, this plate not popular ah. . . . . .
Reply:
In a non-Main function inside are 1
Reply:
Remember seeing in a document, do not believe retaincount
Reply:
Hello, I did not understand what you mean, can answer it. . Why are there non-main 1
Reply:
Group where someone said earlier, you can not believe retaincount, also had a similar strange problem,
Thank you for your reply
,
Reply:
Then I say something, the memory release takes time, asynchronous, before the actual release but also for a lot of us do not know about the operation. What specific things we do not know. Open source BSD did not see ah
You print it out at this place, indicating that moment in a state does not fully reflect the true state of the program has finished running. If so, Xcode will not have a memory leak checking tools to help you check out, you can check at the end.
Reply:
[Pool release]; After foo is released, then you go on foo operations are illegal. May occasionally not crash but it is difficult to ensure that!
Reply:
Thank you
No comments:
Post a Comment