Is there an easy way to simulate low memory inside the emulator ? I'm interested to perform resource cleanups similar to this post
有没有一种简单的方法来模拟模拟器中的低内存?我有兴趣执行类似于这篇文章的资源清理
3 个解决方案
#1
23
Invoke ulimit
command from the shell.
从shell调用ulimit命令。
ulimit -Sv 10000
This will set current memory limit to 10 000 Kb, so that all apps invoked from this shell afterwards won't be able to access more memory.
这会将当前内存限制设置为10 000 Kb,以便之后从此shell调用的所有应用程序将无法访问更多内存。
#2
1
If you're just looking to trigger your onTrimMemory callbacks, then this will do the trick:
如果您只是想触发onTrimMemory回调,那么这将解决这个问题:
adb shell am send-trim-memory
adb shell am send-trim-memory
e.g. adb shell am send-trim-memory com.example.app MODERATE
例如adb shell am send-trim-memory com.example.app MODERATE
#3
0
Another way to do this, if your phone or emulator has application Dev Tools (each emulator has). Open Dev Tools, navigate Development Settings and turn on "Immediatly destroy activities" checkbox. This can help you emulate situation when your activity destroyed as on low memory
另一种方法是,如果您的手机或模拟器具有应用程序开发工具(每个模拟器都有)。打开开发工具,导航开发设置并打开“立即销毁活动”复选框。这可以帮助您模拟当您的活动在内存不足时被销毁时的情况
#1
23
Invoke ulimit
command from the shell.
从shell调用ulimit命令。
ulimit -Sv 10000
This will set current memory limit to 10 000 Kb, so that all apps invoked from this shell afterwards won't be able to access more memory.
这会将当前内存限制设置为10 000 Kb,以便之后从此shell调用的所有应用程序将无法访问更多内存。
#2
1
If you're just looking to trigger your onTrimMemory callbacks, then this will do the trick:
如果您只是想触发onTrimMemory回调,那么这将解决这个问题:
adb shell am send-trim-memory
adb shell am send-trim-memory
e.g. adb shell am send-trim-memory com.example.app MODERATE
例如adb shell am send-trim-memory com.example.app MODERATE
#3
0
Another way to do this, if your phone or emulator has application Dev Tools (each emulator has). Open Dev Tools, navigate Development Settings and turn on "Immediatly destroy activities" checkbox. This can help you emulate situation when your activity destroyed as on low memory
另一种方法是,如果您的手机或模拟器具有应用程序开发工具(每个模拟器都有)。打开开发工具,导航开发设置并打开“立即销毁活动”复选框。这可以帮助您模拟当您的活动在内存不足时被销毁时的情况