Re: NSData dataWithBytes:length:
Re: NSData dataWithBytes:length:
- Subject: Re: NSData dataWithBytes:length:
- From: Greg Titus <email@hidden>
- Date: Thu, 3 Jul 2003 11:52:35 -0700
On Thursday, July 3, 2003, at 11:03 AM, Brent Gulanowski wrote:
I need some help with memory management. I am led to understand that
factory methods provide autoreleased objects.
However, according to MallocDebug and top, memory used up by NSData
objects created using +dataWithBytes:length: seems never to be
released. I wrote a test program:
When you use +dataWithBytes:length:, the method makes a new copy of
those bytes, then when the NSData object is cleaned up by the
autorelease pool, that extra copy is freed. But the original data that
you malloc()ed in the first place is still sitting there. It is that
memory that is building up.
You want to be using +dataWithBytesNoCopy:length:. Not only does this
not copy the memory unnecessarily, but it also takes ownership of the
pointer and frees it when the data goes away. (See the documentation
for NSData on that.)
So I guess the real question is, does MallocDebug/top or the
underlying architecture actually show when the memory is freed?
Yep.
I need some more tools.
OmniObjectMeter is great for this kind of thing (plug plug), but the
above should presumably fix your problem.
Hope this helps,
- Greg
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.