Re: After Autoreleasing Still Getting Leaked
Re: After Autoreleasing Still Getting Leaked
- Subject: Re: After Autoreleasing Still Getting Leaked
- From: Scott Ribe <email@hidden>
- Date: Wed, 15 Jun 2011 11:57:26 -0600
On Jun 15, 2011, at 11:38 AM, Bing Li wrote:
> According to your suggestions, the code is changed as follows. But the leaks are still notified by Instruments. But in Activity Monitor, the program works fine. I feel weird about that. Could you figure out the problem? Thanks!
OK, 1st, your buffer length logic is now correct. But I don't think you need the 0 at the end of the buffer for any reason. You can just have a 1024 byte buffer, and read up to 1024 bytes into it.
2nd, this method looks correct to me. So in order to leak the message, you're leaking it somewhere else. As with your prior question and its answers, instruments only tells you where the leaked object was allocated. It cannot tell you where the bug is. I would guess that somewhere early in notifyMessageReceived: you retain the string, and then you do not ever release it. If you're going to keep it around (especially if you're going to send it to another thread), you need to retain it, so that part is likely correct. (Although if you happen to process it and are done with it before notifyMessageReceived: returns then you don't need to retain it.) So then the issue is that you don't release/autorelease it when you're done with it. But that's just my guess. It could just as well be that where you should retain it, you do so inadvertently in two different places, then only release once. Or all sorts of other combinations of errors. The point is, somewhere later on you're not following the memory management rules with regard to ownership of the receivedMessage string.
--
Scott Ribe
email@hidden
http://www.elevated-dev.com/
(303) 722-0567 voice
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden