NSData release is not reclaiming memory
Posted
by ctpenrose
on Stack Overflow
See other posts from Stack Overflow
or by ctpenrose
Published on 2010-04-29T20:53:56Z
Indexed on
2010/04/29
20:57 UTC
Read the original article
Hit count: 320
iPhoneOS 3.2
I use NSKeyedUnarchiver's unarchiveObjectWithFile: to load a custom object that contains a single large NSData and another much smaller object. The dealloc method in my custom object gets called, the NSData object is released, its retainCount == 1 just before. Physical memory does not decrement by any amount, let alone a fraction of the NSData size, and with repetition memory warnings are reliably generated: I have test until I actually received level 2 warnings. =(
NSString *archivePath = [[[NSBundle mainBundle] pathForResource:@"lingering"]
ofType:@"data"] retain];
lingeringDataContainer = [[NSKeyedUnarchiver unarchiveObjectWithFile:archivePath] retain];
[archivePath release];
[lingeringDataContainer release];
and now the dealloc....
- (void) dealloc {
[releasingObject release];
[lingeringData release];
[super dealloc];
}
Before release:
(gdb) p (int) [(NSData *) lingeringData retainCount]
$1 = 1
After:
(gdb) p (int) [(NSData *) lingeringData retainCount]
Target does not respond to this message selector.
© Stack Overflow or respective owner