Hi,
I’m having a memory leak on my project (web player non-streamed) so i started investigating into it and I’ve found out that with a completly new and empty project (not a single scene/file in the project) a web player build leaves a ~0.5/1MB leak in the system memory every single time you create and destroy the unity object (according to the task manager, tested on firefox&chrome)
I think the problem could be in the way i create/destroy the unity object.
My unity web game is part of a dynamic page so I’m creating the unity object when I need to play the game, destroy it straight after the player finish the session and then rebuild it again when needed etc… always without leaving the current page.
I’m currently filling/hiding a div using jscript/jquery
to create the object I use:
$(‘#’ + unity_div_id).html(objectHTML.toString());
where objectHTML is e StringBuilder with all the “<object id=UnityObject … > … ” appended
and I destroy it with a simple
$(‘#’ + unity_div_id).html(“”);
is it the correct way to do this?
do i need to call any function in the unity game?
I’m actually having a 4/8MB leak in my game (I make an “intensive” use of assetbundles so i wrote a “Destructor” in my main “Game” object
void OnDisable () {
if (!gameObject.active)
{
// Debug.LogError("OnDestroy start");
for (int i = (int)ASSET_BUNDLE_ID.N_BUNDLES-1; i>=0; i--)
{
if (m_asset_bundles[i]!=null)
{
m_asset_bundles[i].Unload(true);
m_asset_bundles[i] = null;
}
}
System.GC.Collect();
// Debug.LogError("OnDestroy end");
}
}
where m_asset_bundles is an array containing all the loaded bundles.
I’m sure that this function gets called when I hide the UnityObject with the jquery posted above but not all the memory get released (I’ve also tried with OnApplicationQuit on the same object without any luck, it gets called before the destructor so i prefer to leave the unload there).
Any suggestions will really be appreciated.
Thank you