• 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: Jean-Daniel Dupas <email@hidden>
  • Date: Mon, 8 Sep 2008 00:39:43 +0200


Le 8 sept. 08 à 00:25, Nick Zitzmann a écrit :

I've got a C data structure in a GC-enabled app. I'm deallocating the structure when the parent object is finished, in -dealloc and - finalize. I've found out the hard way that the data structure is not thread-safe, and eventually causes a crash if deallocated on a thread other than the main thread. Of course, when GC is running, most deallocations occur on another thread.

So I've looked in the documentation and haven't found anything. Is there a way to force a collected object to be finalized on the main thread, and nowhere else? If so, then how do I do this?

I already tried:

1. Calling -performSelectorOnMainThread:... in the -finalize method. Of course it caused the object to be resurrected, which just made the problem worse.
2. Allocating the parent object in an unscanned zone, hoping that retain/release would make a comeback, but it didn't.


Nick Zitzmann
<http://www.chronosnet.com/>

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.

}



_______________________________________________

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

  • Prev by Date: Forcing finalization on the main thread?
  • Next by Date: Re: Forcing finalization on the main thread?
  • Previous by thread: Forcing finalization on the main thread?
  • Next by thread: Re: Forcing finalization on the main thread?
  • Index(es):
    • Date
    • Thread