Releasing an NSBundle
Releasing an NSBundle
- Subject: Releasing an NSBundle
- From: Dave DeLong <email@hidden>
- Date: Mon, 21 Dec 2009 11:06:18 -0700
Hi everyone,
I'm working on a simple plugin-based Foundation tool, and I have a question regarding NSBundles.
I have a function in my tool that discovers all classes that conform to my plugin protocol. It does this by iterating through the list of loaded classes and testing each class to see if it conforms to my plugin protocol. If it does, it adds that class to an array for later use.
This function also looks inside a plugins directory for plugins that might be created later to add extra functionality. It creates an NSBundle object for each item in the plugins directory, and then tries to retrieve the principalClass from the bundle to test for protocol conformance. If the class is compliant, it gets added to the list. If it doesn't, the bundle gets explicitly unloaded. However, after either case, the NSBundle object itself is released, because once I have the class object, I don't need the bundle object itself anymore.
Here's the basic idea of what I'm doing (minus obvious error checking, etc)
for (NSString * potentialPluginPath in pluginFolder) {
NSBundle * plugin = [[NSBundle alloc] initWithPath:potentialPluginPath];
[plugin load];
Class principalClass = [plugin principalClass];
if ([principalClass conformsToProtocol:myPluginProtocol]) {
[plugins addObject:principalClass];
} else {
[plugin unload];
}
[plugin release];
}
My question is this (and the documentation, from what I've seen, is mute on the subject): when an NSBundle object is deallocated, is its associated code automatically unloaded, or does it stay loaded in the runtime?
Thanks!
Dave
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