Re: NSData dataWithBytes:length:
Re: NSData dataWithBytes:length:
- Subject: Re: NSData dataWithBytes:length:
- From: Brent Gulanowski <email@hidden>
- Date: Thu, 3 Jul 2003 15:35:29 -0400
On Thursday, July 3, 2003, at 03:15 PM, Thomas Finley wrote:
On Thursday, July 3, 2003, at 02:03 PM, Brent Gulanowski wrote:
bytes = (char *)malloc(length);
One obvious memory leak is this. +dataWithBytes:length: creates data
that is a _copy_ of the specified memory block. It does not merely
reference the memory block. I repeated your experiment while freeing
"bytes" after creating the data item, and I did not observe anything
out of line while viewing with "top". I also repeated your experiment
with +dataWithBytesNoCopy:length: (and not freeing "bytes" this time),
which seems closer to what your intentions and expectations are, and
also observed no memory leak. This can easily explain your problems.
Look at all the time I wasted. Sorry everyone. Anyway I found the error
in my -setData method, of course, which I was confused about because of
a change in the design a couple of weeks ago. I was leaking really
badly. I wish MallocDebug had been able to identify the leaks, though,
because for some reason, when I asked for leaks, it didn't find any of
note. No excuse... bad programmer.
--
Brent Gulanowski email@hidden
We've heard that a million monkeys at a million keyboards could produce
the Complete Works of Shakespeare; now, thanks to the Internet, we know
this is not true.
_______________________________________________
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.