[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Possible NSAttributedString bug
From: |
Fred Kiefer |
Subject: |
Re: Possible NSAttributedString bug |
Date: |
Thu, 01 Oct 2009 16:42:14 +0200 |
User-agent: |
Thunderbird 2.0.0.23 (X11/20090817) |
I don't think this is a bug in GNUstep, there rather is a problem in
your code. You don't own the attr object as it is created via
dictionaryWithObjectsAndKeys: and still you release it.
I am surprised that this works on Apple.
Cheers
Fred
Derek Fawcus schrieb:
> I suspect there is a bug here (and maybe in the mutable version as well - I
> haven't tried it),
> in that '-initWithString:attributes:' does not retain the attribute
> dictionary.
>
> Using the following chunk of code:
>
> static NSTextStorage *textStorage;
>
> void do_tv (void)
> {
> NSDictionary *attr;
> NSAttributedString *text;
> NSMutableParagraphStyle *ps =
> [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
> [ps setAlignment: NSLeftTextAlignment];
> [ps setLineBreakMode: NSLineBreakByCharWrapping];
>
> attr = [NSDictionary dictionaryWithObjectsAndKeys:
> ps, NSParagraphStyleAttributeName,
> nil, nil];
> [ps release];
> text = [[NSAttributedString alloc]
> initWithString: @"This is the default string.\n"
> attributes: attr];
> [attr release];
>
> textStorage = [[NSTextStorage alloc] init];
> [textStorage appendAttributedString: text];
> [text release];
>
> ...
>
> I find that the app displaying the text crashes. Removing the release of attr
> prevents the crash, but would seem to leak memory. The above works on OSX
> 10.4.11;
> and I was finding it failing on base-1.18, gui/back-0.16
>
>>From a quick glance at the code, I suspect something is wrong in
>>GSAttributedString
> where the code attempts to 'cache' the attributes, and refers to making a
> shallow
> copy without copying objects.
>
> DF
>
>
> _______________________________________________
> Gnustep-dev mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/gnustep-dev
>