Over-released Paragraph Style - Driving Me NUTS!
Over-released Paragraph Style - Driving Me NUTS!
- Subject: Over-released Paragraph Style - Driving Me NUTS!
- From: Seth Willits <email@hidden>
- Date: Thu, 19 Oct 2006 18:07:27 -0700
PLEASE OH PLEEEEEEEEAAAAAAAAASSSSSSSEEEEEEEEEEE HELP ME!!!!!
Hi,
I have a paragraph style that's being over released somehow and for
the life of me I can't figure it out. I appear to have narrowed it
down to the code below, but it doesn't make any sense to me how this
is causing a problem. The code below is tweaked to make it simpler
for appearance and limiting class involvement, but it's functionally
identical as the actual code.
In a singleton class I have a paragraph style being created and set:
- (void)setDefaultParagraph:(NSParagraphStyle *)paragraph
{
[paragraph retain];
[defaultParagraph release];
defaultParagraph = paragraph;
}
- (NSParagraphStyle *)defaultParagraph
{
return defaultParagraph;
}
- (NSParagraphStyle *)buildParagraphStyle:(NSFont *)font;
{
NSMutableParagraphStyle * ps = [[[NSMutableParagraphStyle alloc]
init] autorelease];
...
return ps;
}
- (id)init;
{
defaultParagraph = [[self buildParagraphStyle:font] retain];
}
Pretty straight forward and correct so far...
This seems to be the part causing the problem. In a NSTextStorage
subclass:
- (NSDictionary *)attributesAtIndex:(unsigned)index effectiveRange:
(NSRange *)r
{
.......
NSMutableDictionary * d = [NSMutableDictionary
dictionaryWithDictionary:[language dictionary]];
//// If I simply change the above to d = [NSMutableDictionary
dictionary] the over-release doesn't occur.
[d removeObjectForKey:NSFontAttributeName];
NSMutableDictionary * d2 = [NSMutableDictionary
dictionaryWithDictionary:[store attributesAtIndex:index
effectiveRange:r]];
[d2 addEntriesFromDictionary:d];
.......
return d2;
}
The language class has:
- (id)init;
{
NSParagraphStyle * pgs = [[Singleton defaultInstance]
defaultParagraph];
dictionary = [[NSMutableDictionary alloc] init];
[dictionary setObject:pgs forKey:NSParagraphStyleAttributeName];
}
- (NSDictionary *)dictionary;
{
return dictionary;
}
The over-release is happening in the autorelease pool when a
dictionary is being released. In other words, the stack trace is:
#0 0x9297c008 in -[NSException raise]
#1 0x9297be5c in +[NSException raise:format:]
#2 0x907d32c0 in __CFDictionaryDeallocate
#3 0x907bcf34 in _CFRelease
#4 0x9293d968 in NSPopAutoreleasePool
#5 0x93707d34 in -[NSApplication run]
#6 0x937f887c in NSApplicationMain
#7 0x00011240 in main at main.m:13
*** Selector 'release' sent to dealloced instance 0x15138890 of class
NSMutableParagraphStyle.
The paragraph style is definitely without a doubt the one being
created in the singleton, but what on earth is wrong about the code
above? Am I THAT blind?
--
Seth Willits
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden