Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Autorelease question



Hello,

I have the following code :

if (![fileMgr fileExistsAtPath: indexFilePath]) {
NSMutableDictionary *index = [[NSMutableDictionary alloc] init];
[index setObject: [NSNumber numberWithLong: DEFAULTS_BLOCKSIZE] forKey: INDEXKEY_BLOCKSIZE];
[index setObject: [NSNumber numberWithLong: DEFAULTS_BLOCKSPERPAGE] forKey: INDEXKEY_BLOCKSPERPAGE];
_blockSize = DEFAULTS_BLOCKSIZE;
_blocksPerPage = DEFAULTS_BLOCKSPERPAGE;
if (![index writeToFile: indexFilePath atomically: YES]) {
_dirPath = nil;
NSLog(LOGMSG_INDEXFILENOTWRITABLE);
}
[index release];
} else {
NSDictionary *index = [NSDictionary dictionaryWithContentsOfFile: indexFilePath];
if (nil == [index objectForKey: INDEXKEY_BLOCKSIZE]) {
NSLog(LOGMSG_INDEXFILEOUTOFFORMAT);
_dirPath = nil;
} else
_blockSize = [(NSNumber*)[index objectForKey: INDEXKEY_BLOCKSIZE] longValue];
if (nil == [index objectForKey: INDEXKEY_BLOCKSPERPAGE]) {
NSLog(LOGMSG_INDEXFILEOUTOFFORMAT);
_dirPath = nil;
} else
_blocksPerPage = [(NSNumber*)[index objectForKey: INDEXKEY_BLOCKSPERPAGE] longValue];
[index release];
}


the [index release] on the second branch gives me the following output on the debugger window :

TestRunnrer(1661) malloc: *** error for object 0x112a50: double free
*** set a breakpoint in malloc_error_break to debug

in the enclosing scope I have set up an autorelease pool. What I am suspecting is that when I init the dictionary with a file it is autoreleased, and then the error when I do the release. I this the case ? If so where do I know when some object is created autoreleased or not ? In the NSDictionary's reference page there is nothing mentioned.

Many thanks
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.