I am creating an application and I get an EXC_BAD_ACCESS error.
CODE
@interface DNProjectsCategory : DNCategory {
NSArray *projects;
}
@property(nonatomic, retain) NSArray *projects;
@end
And:
@implementation DNProjectsCategory
@synthesize projects;
// MEM
- (void)dealloc {
[projects release];
[super dealloc];
}
// INIT.
- (id)init {
if (self = [super init]) {
title = NSLocalizedString(@"PROJECTS", nil);
isSubCategory = NO;
// Initialize projects
//!!LINE 32 IS HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
projects = [NSArray arrayWithContentsOfFile:DNPROJECTSFILE];
}
return self;
}
// CATEGORIES
- (NSArray *)subCategories {
NSMutableArray *projectsArray = [[[NSMutableArray alloc] init] autorelease];
for (NSDictionary *project in projects) {
DNCategory *projectCategory = [[DNCategory alloc] initWithTitle:[project valueForKey:@"title"]
subCategories:nil
isSubCategory:YES];
[projectsArray addObject:projectCategory];
[projectCategory release];
}
return projectsArray;
}
CONTENTS OF DNPROJECTSFILE
See http://gist.github.com/618628
CONSOLE & INSTRUMENTS
This is what the Console says when ran (NSZombie is enabled):
run
[Switching to process 41257]
Running…
2010-10-09 23:32:36.899 Done[41257:a0f] *** -[CFString isKindOfClass:]: message sent to deallocated instance 0x1001caab0
sharedlibrary apply-load-rules all
Here is what Instruments says in an NSZombie test:
Zombie Messaged
An Objective-C message was sent to a deallocated object (zombie) at address: 0x10012af80.
Stack Trace
0 CoreFoundation _CFRuntimeCreateInstance
1 CoreFoundation __CFStringCreateImmutableFunnel3
2 CoreFoundation CFStringCreateWithBytes
3 CoreFoundation _uniqueStringForCharacters
4 CoreFoundation getString
5 CoreFoundation parseXMLElement
6 CoreFoundation parseXMLElement
7 CoreFoundation parseArrayTag
8 CoreFoundation parseXMLElement
9 CoreFoundation parsePListTag
10 CoreFoundation parseXMLElement
11 CoreFoundation _CFPropertyListCreateFromXMLStringError
12 CoreFoundation _CFPropertyListCreateWithData
13 CoreFoundation CFPropertyListCreateFromXMLData
14 Foundation _NSParseObjectFromASCIIPropertyListOrSerialization
15 Foundation +[NSArray(NSArray) newWithContentsOf:immutable:]
16 Foundation +[NSArray(NSArray) arrayWithContentsOfFile:]
17 Done -[DNProjectsCategory init] /Users/rsonic/Developer/Done/DNProjectsCategory.m:32
18 Done -[DNBindingsController categories] /Users/rsonic/Developer/Done/DNBindingsController.m:18
19 Foundation -[NSObject(NSKeyValueCoding) valueForKey:]
20 Foundation -[NSObject(NSKeyValueCoding) valueForKeyPath:]
21 AppKit -[NSBinder valueForBinding:resolveMarkersToPlaceholders:]
22 AppKit -[NSArrayDetailBinder _refreshDetailContentInBackground:]
23 AppKit -[NSObject(NSKeyValueBindingCreation) bind:toObject:withKeyPath:options:]
24 AppKit -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:]
25 AppKit loadNib
26 AppKit +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:]
27 AppKit +[NSBundle(NSNibLoading) loadNibNamed:owner:]
28 AppKit NSApplicationMain
29 Done main /Users/rsonic/Developer/Done/main.m:13
30 Done start
QUESTION
I really don't know how to fix this double-release. For as far as I know I don't release the projects
variable anywhere except in dealloc
. Can somebody help me, please? Thanks.