Studio api resources management

Maybe I missed a part of the manual, but I’m still having issues understanding the resource management for the FMOD studio API.

For the general system object it seems clear, create the object Studio::System::create
and destroy it with Studio::System::release

For banks you create the object with Studio::System::loadBankFile? Or is this part of the studio object created above? And a bank object will be destroyed with Studio::System::unload. But will it also set the pointer I used for bank loading to nullptrand/or does it remove the entire pointer?

And similar for instances, Studio::EventDescription::createInstance, will it create a separate object or is it part of the bank or studio object? And I’ve read is common practice the call Studio::EventInstance::release right after Studio::EventInstance::start to mark it for clean up in the update call. Or should I first poll the state and only call release if the instance has stopped playing? And again, will it also set the pointer I’ve used during creation to nullptr and/or does it remove the entire pointer?

Even after unloading banks or releasing systems/events the pointer will remain. However in the Studio API those pointers are actually handles, so using it after free will be an error not a crash.

Creating and releasing events will automatically add and remove them from memory so the only thing to worry about are pointers which, as previously mentioned, are there to prevent hard crashes.

Thanks for your reply. But I don’t know if I get it.

I think I need to create an event instance, store the pointer to the instance in my object, play it, give the release(). Then the instance gets cleaned in the update() call. But then I would assume the pointer in my object is dangling, so dereferencing it would give UB.

To prevent this I would do the usual checks before any dereference.

void F(ptr* instance_ptr) {
    if(instance_ptr == nullptr || !instance_ptr.isValid()) {
        instance_ptr = nullptr;
        return;
    }
    // the actual function body
}

Or doesn’t it work like this and are there other standard ways of dealing with this?

This function is perfectly fine for handling these stopped & released event instances.