# Studio api resources management

**URL:** <https://qa.fmod.com/t/studio-api-resources-management/17880>\
**Category:** FMOD Engine\
**Tags:** cpp\
**Created:** [October 31, 2021, 12:10pm UTC](https://qa.fmod.com/t/studio-api-resources-management/17880 "2021-10-31T12:10:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mca2](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mca2/32/3177_2.png) [@mca2](https://qa.fmod.com/u/mca2)\
**Post date:** [October 31, 2021, 12:10pm UTC](https://qa.fmod.com/t/studio-api-resources-management/17880/1 "2021-10-31T12:10:10Z")

</div>

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 `nullptr`and/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?

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [November 4, 2021, 12:02am UTC](https://qa.fmod.com/t/studio-api-resources-management/17880/2 "2021-11-04T00:02:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mca2](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mca2/32/3177_2.png) [@mca2](https://qa.fmod.com/u/mca2)\
**Post date:** [February 18, 2022, 8:46pm UTC](https://qa.fmod.com/t/studio-api-resources-management/17880/3 "2022-02-18T20:46:07Z")

</div>

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.

```auto
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?

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [February 28, 2022, 2:14am UTC](https://qa.fmod.com/t/studio-api-resources-management/17880/4 "2022-02-28T02:14:23Z")

</div>

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