Forge Viewer内存过高致移动端Webview崩溃问题排查求助
Hey there, great question! From what I've seen working with Forge Viewer, version 6.1 does have some known memory leak issues specifically when running in mobile WebView environments—and that makes sense when you compare it to your Three.js setup.
Three.js is a lightweight core rendering library, so if your large sample only uses basic loading and rendering, it’s less likely to hit edge cases with unmanaged resources. But Forge Viewer builds on top of Three.js with tons of extra layers: BIM data parsing, interactive tools, model caching, event listeners, and DOM integration. These extra features introduce more potential for memory leaks, especially in mobile WebViews which have stricter memory limits and different garbage collection (GC) behavior than desktop browsers.
Common Leak Points in Viewer 6.1 (Mobile WebView)
- Improper Viewer Cleanup: If you’re initializing and destroying Viewer instances multiple times, forgetting to call
viewer.finish()or leaving behind associated DOM elements/event listeners creates lingering references. Mobile WebView GC is less aggressive about cleaning up these cyclic references, leading to memory bloat over time. - Unreleased WebGL Resources: In 6.1, large models can leave behind unused buffer geometries, textures, or shader programs when switching models or navigating away. WebView’s WebGL resource management is stricter than desktop browsers—these leftover resources eat up memory quickly until the app crashes.
- Orphaned Event Listeners: Viewer binds global events (like touch gestures, window resizes) that don’t always get unregistered properly when the Viewer is destroyed. These listeners keep the Viewer instance and related objects from being GC’d.
Steps to Diagnose & Fix
- Verify the Leak: Use Chrome’s remote debugging tools to connect to your mobile WebView. Take memory snapshots before and after extended use—look for growing counts of
Autodesk.Viewing.Viewer3Dinstances, Three.jsBufferGeometry, or unused DOM elements tied to the Viewer. - Upgrade the Viewer Version: Autodesk fixed a ton of memory leak issues in versions 7.x and later, with specific optimizations for mobile environments. Upgrading to a recent stable version is the most impactful fix here.
- Hardened Cleanup Routine: When you’re done with a Viewer instance, make sure to:
- Call
viewer.finish()to trigger internal cleanup - Remove the Viewer’s container DOM element from the page
- Set the Viewer instance variable to
nullto break all reference chains
- Call
- Optimize Mobile Usage: Disable non-essential features to reduce memory load:
- Use
viewer.setQualityLevel(false, false)to turn off shadows and anti-aliasing - Call
viewer.disableSelection()if you don’t need model selection - Load simplified model derivatives (lower LODs) specifically for mobile
- Use
To wrap up: Your Three.js setup doesn’t hit the issue because it’s using a minimal subset of features, while Forge Viewer 6.1’s extra complexity introduces memory management gaps that are amplified in mobile WebViews. Upgrading and tightening your cleanup process should resolve the crashes.
内容的提问来源于stack exchange,提问作者Bryan

