Closed memostark closed 4 years ago
This seems like a bug in Sceneform. If I recall correctly you are supposed to call SceneView.destroy()
from your Activity
's onDestroy()
callback. destroyAllResources()
is a static that you should probably only use when your application terminates.
I forgot to mention that my activity has an ArFragment which calls SceneView.destroy()
whenever is destroyed, just for trying I called that method from my Activity's onDestroy() but the memory is still not released.
I also tried using FilamentAsset.releaseSourceData()
for each RenderableInstance but still no luck.
As Romainguy said, it was a Scenform
1.16 bug. For anyone that has the same problem, I found a workaround:
Go to Sceneform's RenderableInstance
and make Filament's AssetLoader
a member variable
public class RenderableInstance {
AssetLoader loader;
void createFilamentAssetModelInstance() {
....
loader = new AssetLoader( ....
}
}
Create this new method and use the loader to destroy the assets
public void destroyAsset(){
if(filamentAsset != null) {
loader.destroyAsset(filamentAsset);
filamentAsset = null;
}
}
Now you can call this method whenever you need to release the resources, in my case I call it from a custom AnchorNode
class that has a node with a RenderableInstance
I'm using Sceneform 1.16 which leverages Filament 1.7.0 My main activity is a simple list, when I click an item, it opens a new activity with a fragment with AR and loads some GLB models when certain image is detected (some models are up to 15mb in size) however after closing the activity the graphics memory still there. This quickly becomes a problem after I open a couple of items because the app crashes, I assume because of the memory.
I expected the memory to be automatically freed when the activity is closed. I tried to do that manually using Sceneform's SceneView.destroyAllResources(), digging through the code I found out it calls Filament RenderableManager's destroy method for each Renderable Instance, however when I use this method the app crashes.
I tried using this method both before and after destroying the activity and I'm getting the same problem, though sometimes the "Object couldn't be destoyed (double destroy()?)" error was caused at
com.google.android.filament.Engine.destroyTexture(Engine.java:581)
You can see the graphics memory takes the most with 1.2 GB, afterwards the app crashes with no stacktrace.
I also tried updating filament to 1.8.1 but still have the same problems
Sorry if this is not the place to post this, I'm not sure if this is a bug or I'm not using Sceneform and Filament properly.