• 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: Attr Str drawing vs Layout Manager drawing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Attr Str drawing vs Layout Manager drawing


  • Subject: Re: Attr Str drawing vs Layout Manager drawing
  • From: Martin Wierschin <email@hidden>
  • Date: Mon, 11 May 2009 14:32:08 -0700

"You can release the text container because the layout manager retains it,
and you can release the layout manager because the text storage object
retains it."

It's fine as long as you don't continue to use the objects directly. The sample code amounts to this:

id obj1 = [Bar new], obj2 = [Bar new];
[obj1 setFoo:obj2]
[obj2 release];  // All well and good.

[obj2 bazWithQuux:YES]; // NO! We don't own obj2 anymore.

Yes, but the documentation is telling you that "obj1" retains "obj2", so in that case you are assured "obj2" is still valid. Of course, there is the possibility for something crazy like:


static void XXCodeYouDontControlOrForgotYouWrote( NSTextStorage* ts )
{
	NSLayoutManager* lm = [[ts layoutManagers] objectAtIndex:0];
	[ts removeLayoutManager:lm];
	[ts addLayoutManager:[[[NSLayoutManager alloc] init] autorelease]];
}

{
	NSTextStorage* ts = [[NSTextStorage alloc] init];
	NSLayoutManager* lm = [[NSLayoutManager alloc] init];
	[ts addLayoutManager:ts];
	[lm release];

	XXCodeYouDontControlOrForgotYouWrote( ts );
	[lm numberOfGlyphs]; // probably crash
}

So technically you're correct, but maybe paranoid :P

~Martin

_______________________________________________

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


  • Follow-Ups:
    • Re: Attr Str drawing vs Layout Manager drawing
      • From: Kyle Sluder <email@hidden>
References: 
 >Attr Str drawing vs Layout Manager drawing (From: Seth Willits <email@hidden>)
 >Re: Attr Str drawing vs Layout Manager drawing (From: Peter Ammon <email@hidden>)
 >Re: Attr Str drawing vs Layout Manager drawing (From: Kyle Sluder <email@hidden>)
 >Re: Attr Str drawing vs Layout Manager drawing (From: Seth Willits <email@hidden>)
 >Re: Attr Str drawing vs Layout Manager drawing (From: Kyle Sluder <email@hidden>)

  • Prev by Date: [iPhone] UITableView with state?
  • Next by Date: Re: [iPhone] UITableView with state?
  • Previous by thread: Re: Attr Str drawing vs Layout Manager drawing
  • Next by thread: Re: Attr Str drawing vs Layout Manager drawing
  • Index(es):
    • Date
    • Thread