Re: NSData dataWithBytes:length:
Re: NSData dataWithBytes:length:
- Subject: Re: NSData dataWithBytes:length:
- From: Brent Gulanowski <email@hidden>
- Date: Thu, 3 Jul 2003 15:22:20 -0400
On Thursday, July 3, 2003, at 02:51 PM, Aaron Tuller wrote:
You leak becayse you never free the bytes that you malloc.
dataWithBytes: copies the data into a new NSData object, you are
responsible for freeing the malloc-ed bytes, but not the NSData.
If you want to do what you're doing do a dataWithBytesNoCopy:length:
and then NSData will clean up for you when it's dealloc'd.
-aaron
At 2:03 PM -0400 7/3/03, Brent Gulanowski wrote:
// insert code here...
length = sizeof(char)*1000;
bytes = (char *)malloc(length);
data = [NSData dataWithBytes:bytes length:length];
NSLog(@"%@", data );
[pool release];
usleep( 10000 );
GAH! Not much for writing sample apps, am I?
Well now that my credibility is shot .... I fixed the sample, and it
behaves appropriately. Unfortunately I was always freeing the memory in
my real app, so I'm doing something else wrong. I changed to the
"NoCopy" version, and no change in memory appearance, so back to
reading the code.
Thanks,
Brent Gulanowski email@hidden
--
keyboard not found, press F1 to continue
_______________________________________________
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.