• 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: Bundle loading
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bundle loading


  • Subject: Re: Bundle loading
  • From: Douglas Davidson <email@hidden>
  • Date: Thu, 22 Aug 2002 11:24:27 -0700

On Thursday, August 22, 2002, at 10:29 AM, Finlay Dobbie wrote:

However what happens when the host exits? Do my objects get sent the
-dealloc message when the host (a CFM app in my case) exits and my bundle
gets "unloaded"?

I thought that bundles don't get "unloaded" at all, but I could be wrong. You could observe the NSApplicationWillTerminate notification and do cleanup there.

Again, the semantics vary, and it is difficult to make a general statement covering all cases. When it comes to most ordinary memory and OS resources--memory allocations, file descriptors, Mach ports, and so forth--there is no real need for explicit cleanup, because the OS will do all that is necessary automatically, whether the process exits normally or abnormally. If there is something else that needs cleaning up--removing a temporary file, say, or flushing some state to disk--remember in your design that there is no way to guarantee any code will run at termination, since the process may terminate abnormally at any time.

If you do wish to have code run at normal app termination or bundle unloading, there are a number of options at different levels. In Cocoa, there is the above-mentioned termination notification; this would be appropriate for any code that makes use of Cocoa functionality. At the BSD level, there are mechanisms for having code run at exit time. You can also see the runtime architecture documentation for mechanisms specific to particular executable types.

The semantics of dynamically unloading bundles vary, just as the semantics of loading bundles do. NSBundle does not support unloading, but CFBundle does provided the underlying executable format does. For example, MH_DYLIBs cannot be dynamically unloaded, but MH_BUNDLEs can. Remember, though, that unloading of code is an inherently risky operation; it is up to you to make sure there are no dangling pointers to functions or data in the unloaded bundle. In many cases there is no real need to unload a bundle--if the bundle's code is not executed, it will simply page out over time, and no longer affect performance. Of course, there are cases where explicit bundle unloading is necessary or desirable, but it should be done with caution.

Douglas Davidson
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Bundle loading (From: Finlay Dobbie <email@hidden>)

  • Prev by Date: Re: Menu validation not working [SOLVED]
  • Next by Date: Icon classes?
  • Previous by thread: Re: Bundle loading
  • Next by thread: Re: Bundle loading
  • Index(es):
    • Date
    • Thread