I had already tried an NSAutoreleasePool but came across issues, it
released inputString so as useless for the next iteration. So I tried
keeping it around with...
if (inputString != nil) {
[inputString retain]; /* Keep match around. */
}
[inputString release];
within the NSAutoreleasePool ...and then I'm back to square one.
I understand the release retain concept reasonably well, it's just
that as inputString was being replaced by a pointer of the same name I
presumed the old one was autoreleased OR just replaced the address
location.
So, how do I keep a copy hanging around AND kill the mysterious new
copy then (which shares the same name as the old one presumably)?
Not really; the pointer to the old address is still hanging around
out there until you ensure that it's taken care of. In this case,
yes, the stringByReplacing... method *does* return an autoreleased
object, which will *eventually* get cleaned up, but since you're
doing this in a tight loop, all that eventual cleanup is not going
to be done until (possibly) much later. If you wrap the contents of
your while loop with
NSAutoreleasePool *pool = [NSAutoReleasePool new];
...
[pool drain];
This will clean up the autoreleased inputString each time, instead
of collecting them all for later disposal.
See the Cocoa and Objective-C docs on Memory Management.
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com