Based on my knowledge of spine-android, you can actively release resources to free up memory when your app goes to the background. Here's how:
Manual Resource Cleanup
When using AndroidSkeletonDrawable, you should explicitly dispose of resources when they're no longer needed:
// In your Activity/Fragment onDestroy() or when going to background
if (drawable != null) {
drawable.dispose();
drawable = null;
}
// Also dispose the atlas if you're managing it separately
if (atlas != null) {
atlas.dispose();
atlas = null;
}
// Dispose skeleton data if no longer needed
if (skeletonData != null) {
skeletonData.dispose();
skeletonData = null;
}
Important Disposal Guidelines
Following spine-android's memory management patterns:
- Dispose in the correct order: Dispose drawables/skeletons before disposing shared data (SkeletonData, Atlas)
- Shared resources: If multiple drawables share the same
SkeletonData or Atlas, only dispose these shared resources when ALL instances using them are done
- Texture cleanup: Disposing the
Atlas will automatically dispose associated OpenGL textures through the texture loader
For Background State Management
In your Activity's lifecycle:
@Override
protected void onPause() {
super.onPause();
// Optionally dispose resources when going to background
cleanupSpineResources();
}
@Override
protected void onDestroy() {
super.onDestroy();
// Always dispose resources here
cleanupSpineResources();
}
private void cleanupSpineResources() {
if (drawable != null) {
drawable.dispose();
drawable = null;
}
// Dispose other resources as needed
}
Memory Consideration
The 77MB native heap you're seeing is likely from loaded textures and skeleton data. Proper disposal should free this memory. If memory isn't being released after disposal, ensure you're:
- Calling
dispose() on all Spine objects
- Not holding references to disposed objects
- Disposing in the correct order (instances before shared data)
Make sure your spine-android version (4.2.10) matches the Spine Editor version you exported from for proper compatibility.