• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: exceptions when NSTextStorage initialized with empty string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: exceptions when NSTextStorage initialized with empty string


  • Subject: Re: exceptions when NSTextStorage initialized with empty string
  • From: Martin Hewitson <email@hidden>
  • Date: Wed, 7 Apr 2010 18:54:34 +0200

Yes, they are. Sorry, I was over selective in my first post in an attempt to just show the salient points. Here's a more complete excerpt from the code that sets up the text storage etc:

		// Get the string from the File entity
		NSError *error = nil;
		NSString *str = [[NSString alloc] initWithData:[file valueForKey:@"content"]
						      encoding:NSUTF8StringEncoding];
		if (error) {
			[NSApp presentError:error];
			return nil;
		}

		// Setup undo manager for this file
		undoManager = [[NSUndoManager alloc] init];

		// Setup a text storage to hold this string
		NSMutableAttributedString *attStr = [[[NSMutableAttributedString alloc] initWithString:str] autorelease];

		textStorage = [[NSTextStorage alloc] initWithAttributedString:attStr];

		// Add a main layout manager
		NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
		[layoutManager setAllowsNonContiguousLayout:NO];
		[textStorage addLayoutManager:layoutManager];

		// Now add the container to the layout manager
		NSTextContainer *textContainer = [[NSTextContainer alloc] init];
		[layoutManager addTextContainer:textContainer];

		// Clean up
		[textContainer release];
		[layoutManager release];
		[str release];


I think that's all ok, but I could be wrong. Again, the main point seems to be that this works as long as "str" is not empty. If it is, then I get those exceptions when the first character is typed in the text view.

Thanks again,

Martin



On Apr 7, 2010, at 6:27 PM, Stephen J. Butler wrote:

> On Wed, Apr 7, 2010 at 1:31 AM, Martin Hewitson
> <email@hidden> wrote:
>>                // Clean up
>>                [textContainer release];
>>                [layoutManager release];
>>                [str release];
>
> Are you sure that all these are balanced releases? The only one you
> show allocating is layoutManager. In particular, the [str release]
> concerns me.
> _______________________________________________
>
> 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:
>
> This email sent to email@hidden

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Martin Hewitson
Albert-Einstein-Institut
Max-Planck-Institut fuer
    Gravitationsphysik und Universitaet Hannover
Callinstr. 38, 30167 Hannover, Germany
Tel: +49-511-762-17121, Fax: +49-511-762-5861
E-Mail: email@hidden
WWW: http://www.aei.mpg.de/~hewitson
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





_______________________________________________

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:

This email sent to email@hidden

References: 
 >exceptions when NSTextStorage initialized with empty string (From: Martin Hewitson <email@hidden>)
 >Re: exceptions when NSTextStorage initialized with empty string (From: "Stephen J. Butler" <email@hidden>)

  • Prev by Date: Re: Table view question
  • Next by Date: iPad: Device Orientation
  • Previous by thread: Re: exceptions when NSTextStorage initialized with empty string
  • Next by thread: OS X Game Programming
  • Index(es):
    • Date
    • Thread