• 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: Forcing finalization on the main thread?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Forcing finalization on the main thread?


  • Subject: Re: Forcing finalization on the main thread?
  • From: Bill Bumgarner <email@hidden>
  • Date: Sun, 07 Sep 2008 17:21:10 -0700

On Sep 7, 2008, at 3:53 PM, Nick Zitzmann wrote:
On Sep 7, 2008, at 4:39 PM, Jean-Daniel Dupas wrote:

You can use perform on main thread using a class method and pass your structure as argument.


That worked; thanks. I wouldn't have guessed it, since that method wasn't documented as a class method, but it worked anyway...

Code Fragment:

Just a idea like that.
You can use perform on main thread using a class method and pass your structure as argument.


+ (void)finalize {
[[self class] performSelectorOnMainThread:@selector(destroyNotThreadSafeStruct:) withObject:[NSValue valueWithPointer:myStruct]];
}


+ (void)destroyNotThreadSafeStruct:(id)myStruct {
void *struct = [myStruct pointerValue];
// perform cleanup. As this is a class method, it does not resurect the object.

}

Yup. That is the way to do it. Whatever you do, *do not block in your -finalize methods*. Especially if you blocking on main thread processing.


Very Bad Things Can Happen.

Notably, your performance can go to hell. And it is quite easy to lock things up.

In this case, the above pattern should not cause that to happen.

In general, -finalize should *only be used to release memory not being managed by GC*.

b.bum

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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: 
 >Forcing finalization on the main thread? (From: Nick Zitzmann <email@hidden>)
 >Re: Forcing finalization on the main thread? (From: Jean-Daniel Dupas <email@hidden>)
 >Re: Forcing finalization on the main thread? (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Re: Forcing finalization on the main thread?
  • Next by Date: Re: Interface Builder changing size of controls...
  • Previous by thread: Re: Forcing finalization on the main thread?
  • Next by thread: Re: Forcing finalization on the main thread?
  • Index(es):
    • Date
    • Thread