I’ve got a problem in the way I’m managing my asset database and I believe I’ve tracked down the reason why I have a leak… a pretty big one; however, I’m just not sure how to completely fix this.
My base class is a ScriptableObject and my main asset is basically a List<> of that class. I have add, update, remove methods in which I pass back a reference copy(?) to a controlling class for the asset database.
(main asset, addobject method)
public LockBase AddObject(string e)
{
_tmp = CreateInstance<LockBase>();
_tmp.ObjectID = e;
_tmp.Locked = false;
_tmp.name = "UniqueID";
m_guid.Add(_tmp);
return _tmp;
}
The controlling class handles all asset database methods such as creation, validation, and methods for use with editors (inspector, windows… whichever). The editor passes the object identifier to the controlling class which verifies it and/or adds the identifier to the asset database (the main asset class handles adding to the list).
(controlling class, addguid method [if it doesn’t exist in the asset database])
public void AddGUID(string _guid)
{
if (!CheckGUID(_guid))
{
LockBase _object = locker.AddObject(_guid);
AssetDatabase.AddObjectToAsset(_object, locker);
EditorUtility.SetDirty(locker);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
}
The controlling class is not reporting any leaks, nor is the main asset… however, the base class is reporting… thousands. And I believe it has to do with how I created the “_tmp” instance of it in main assets’ methods. Assigning HideAndDontSave flag clears up the leaks just dandy; however, i’m introduced to a new error:
o->TestHideFlag (Object::kDontSave) && (options & kAllowDontSaveObjectsToBePersistent) == 0
I believe this has to do with the reference copy being given back to the controlling class from the main asset (it returns _tmp object for the controller to add the resource to the database).
Should I just remove the hide flags from _tmp for this operation and just deal with the leaks, or how should I handle this?