Can I flag a Cocoa bundle so that an application cannot unload it until the app quits?

Referencing this question from 2 years ago...
https://developer.apple.com/forums/thread/100321

and this from CFBundle documentation...
"When the last reference to the CFBundle object is released and it is finally deallocated, then the code will be unloaded if it is still loaded and if the executable is of a type that supports unloading."
https://developer.apple.com/documentation/corefoundation/cfbundle?language=objc

If I am writing a Cocoa bundle (e.g. an audio VST plugin) that is third party to the applications (e.g. digital audio workstations DAWs) that load and run it, how can I prevent an application from trying to unload it? Can I flag it in some way to force it to stay in memory until the application quits?

Thank you

Replies

flag it in some way to force it to stay in memory 

The OS decides what/when to purge for it's own needs, meaning even if your app found a way, the risk of being overridden could arbitrarily negate your scheme, I think.
If an application calls CFBundleUnloadExecutable on a bundle that links to the Objective-C runtime the inference of the above referenced documents is that the Objective-C runtime will get corrupted. Surely macOS could catch this case and block CFBundleUnloadExecutable from doing the unload? Or provide some mechanism to define such a bundle as "not unloadable"?

If you're concerned purely about reference counting, you could simply take an extra reference during your loading mechanism, but there also seems to be some confusion about whether this is Cocoa (ObjC) or CoreFoundation (C/C++).
Perhaps you could talk a little about why this particular bundle needs to stay resident?