NSData dataWithBytes:length:
NSData dataWithBytes:length:
- Subject: NSData dataWithBytes:length:
- From: Brent Gulanowski <email@hidden>
- Date: Thu, 3 Jul 2003 14:03:06 -0400
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:
#import <Foundation/Foundation.h>
#include <unistd.h>
int main (int argc, const char * argv[]) {
int i;
size_t length;
char *bytes;
NSData *data;
for(i = 0; i< 1000; i++ ) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// insert code here...
length = sizeof(char)*1000;
bytes = (char *)malloc(length);
data = [NSData dataWithBytes:bytes length:length];
NSLog(@"%@", data );
[pool release];
usleep( 10000 );
}
while(1);
return 0;
}
So I guess the real question is, does MallocDebug/top or the underlying
architecture actually show when the memory is freed? With small memory
it is no big deal, but my program allocates a lot of memory for
temporary usage -- a 64MB block, and then 16 4MB blocks (the latter set
for making textures). I have checked that retains and releases are
balanced -- in any case, the test program shows the same behaviour: the
memory is allocated and appears to never be released. It is also not
reported as a leak, meaning that it is really being freed? In my
application, if I close the document which creates the data and open a
new document, I can hear virtual memory kicking in, and watch the
memory usage increase dramatically, so I am doubting that the data is
being freed. I need some more tools.
Brent Gulanowski
--
Mac game development news and discussion
http://www.idevgames.com
_______________________________________________
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.