Memory Optimization
Miniapps run within limited system resources. When memory usage is too high, the miniapp may be destroyed by the system or proactively reclaimed by the client, forcing users to reopen it — a very poor experience.
Symptoms of Memory Issues
Listen for Memory Warnings
Use onMemoryWarning to listen for memory warning events and perform necessary cleanup when a warning is received:
Avoid Memory Leaks
Clean Up Timers Promptly
Timers associated with a component must be cleaned up when the component unmounts:
Unbind Event Listeners Promptly
Registered event listeners should be unbound when the component unmounts:
Control Page Stack Depth
A deep page stack consumes large amounts of memory. Choose navigation methods wisely:
Control Data Scale
Avoid storing excessively large data in state or global variables. Use pagination to keep only the data needed for the current view:
Control Package Size
Package size not only affects download time, but also directly impacts runtime memory. The package must be parsed and executed when loaded; the larger the package, the more memory it consumes. Reducing package size is an effective way to lower the memory baseline.
See Package Size Optimization.