• 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: (void *)contextInfo
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (void *)contextInfo


  • Subject: Re: (void *)contextInfo
  • From: Seth Willits <email@hidden>
  • Date: Tue, 12 Jan 2010 12:01:51 -0800

On Jan 12, 2010, at 11:51 AM, Rainer Standke wrote:

> NSArray *theContextInfo = [[NSArray alloc] init];
> 	theContextInfo = [NSArray arrayWithObject:objTBD];

Well that's a leak already... The alloc/init is a waste.



> 	[NSApp beginSheet: alertWindow
> 	   modalForWindow: [self windowForSheet]
> 		modalDelegate: self
> 	   didEndSelector: @selector(didEndSheet:returnCode:contextInfo:)
> 		  contextInfo: theContextInfo];

And here you passed an autoreleased object as the context info which means it's going to be deallocated at the end of the run loop. You should be passing a retained object to context info...



> - (void)didEndSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
> {

And grabbing it here, and releasing it somehow to balance the retain.
	NSArray * array = [(NSArray *)contextInfo autorelease];



> The contextinfo's class is logged as NSConcreteMutableData.

Because that pointer is now pointing at entirely different object. Your array has already been deallocated and an NSMutableData instance took its place.



> Why is contextinfo considered to be of class void in the signature?

Because void * can be a pointer to *anything*. contextInfo is not just limited to Obj-C objects. You could pass a pointer to an integer if you wanted. (It's even not out of the question to pass an integer value directly to contextInfo instead of using a pointer to one.)


--
Seth Willits



_______________________________________________

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: 
 >(void *)contextInfo (From: Rainer Standke <email@hidden>)

  • Prev by Date: (void *)contextInfo
  • Next by Date: Re: (void *)contextInfo
  • Previous by thread: (void *)contextInfo
  • Next by thread: Re: (void *)contextInfo
  • Index(es):
    • Date
    • Thread