Game Development Community

Memory problem with AssetDataBase

by Villa Hirschberg · in Torque 2D Professional · 10/12/2015 (9:03 am) · 6 replies

Hi together,

we have the problem that the memory runs full. We use strictly PrivateAssets, so we load them with AssetDatabase.addPrivateAsset (%asset). When we want to delete them because they are no longer needed, we first use AssetDatabase.releaseAsset(%myPrivateAsset) and then AssetDatabase.removeDeclaredAsset (%myPrivateAsset). So the Asset is deleted, but the memory usage stays the same. So if we play a level for several times the memory runs full. On the iPad it results in a crash!
Does anybody know this? How can we handle this problem or is there a different way to remove asset from the memory?

Some more information: we used Torque Script code from a project that was built with the Torque 3D Game Engine (version 1.5.2). We can run this game on the iPad, but it crashes after some levels.
We have a lot graphics and sounds we have to load for a level, their are unique for each level, so we want to delete them after finishing a level.

We would be glad about some help or information!

Thanks

Hans

#1
10/12/2015 (4:07 pm)
Private assets were never meant to be used this way. The original intent was for creating temporary assets when importing using the 3-Step Studio tools. I'm guessing that there would be at least a little work involved in finding and removing this memory leak.

With normal assets the actual image or sound file can be released when there are no more references to the asset handle.
#2
11/03/2015 (4:09 am)
Thanks a lot. We moved our assets to taml files. We found that the sound files are the problem. The GPU memory is getting cleared, but audio assets stay in memory even when released. We tried to stream the audio. Then no memory is allocated, but the audio hangs after some time when looping. We found that the audio files are released directly after allocation (Reference count 1->0, streaming or not):

--------------------------------------------------------------------------------
Asset Manager: Started acquiring Asset Id 'SWGK:menu_music'...
Asset Manager: > Loading asset into memory as object Id '2635' from file 'D:..../modules/SWGK/1/swgk/data/sound/music/music_menu.taml'.
Asset Manager: > Finished acquiring asset. Reference count now '1'.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Asset Manager: Started releasing Asset Id 'SWGK:menu_music'...
Asset Manager: > Reference count now '0'.
Asset Manager: > Finished releasing Asset Id 'SWGK:menu_music'.
--------------------------------------------------------------------------------

Is that the way it should work?
#3
11/04/2015 (5:50 am)
Sounds like a bug somewhere. Might be iOS/MacOS specific.

My understanding is that if the reference count is 0 and the asset is released it should be dropped from memory. Streaming or not shouldn't matter for this - streaming is basically there so that large files (music, for instance) start playing quickly and load as they go. Once they're finished loading that should be it.

Looping sounds should not hang regardless, but that might be a flaw in OpenAL. Creative Labs dropped development on that ages ago and I don't know who (if anyone) is now maintaining that - if that turns out to be the case. Let me see if I can find the source I had checked out back in the day....
#4
11/17/2015 (3:24 am)
We see that happen on Windows (not only iOS). What we tried now is to load and unload a module containing only one sound/music asset:

function swgk_mainMenuGui::debug_loadModule(%this){
ModuleDatabase.LoadExplicit( "Sound" );
}

function swgk_mainMenuGui::debug_playSound(%this){
%this.debugSoundHandle = alxPlay("Sound:debugSound");
}

function swgk_mainMenuGui::debug_stopSound(%this){
alxStop( %this.debugSoundHandle );
%this.debugSoundHandle = "";
//AssetDatabase.deleteAsset("Sound:debugSound", true, true);
//AssetDatabase.releaseAsset("Sound:debugSound");
//AssetDatabase.removeDeclaredAsset("Sound:debugSound");
}

function swgk_mainMenuGui::debug_unloadModule(%this){
ModuleDatabase.unloadExplicit( "Sound" );
AssetDatabase.purgeAssets();
}

taml asset file:

<AudioAsset
AssetName="debugSound"
AssetAutoUnload="0"
AudioFile="test.wav" />


Loading and unloading the module works, but it did not help. The memory for the sound data (16 MB .wav file) is not released. It gets allocated on playing the sound, but it is never released again.
May there be a missing call in the engine code? .. or as you proposed in the OpenAL?

#5
04/28/2016 (3:32 am)
Hello again,

our last post is long time ago. We still have this problem. Without fixing it we can't finish our project. So does someone has the same problem or maybe could fix it?

We would be glad if someone has a solution or an idea how to fix this memory leak.

Thanks

Hans
#6
04/28/2016 (5:47 am)
If you were to report this issue here (https://github.com/GarageGames/Torque2D) you might see faster results.

Few people in the community actively use these forums any more - most hang out at torque3d.org now. Though posting both places might help, too.