آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

استفاده از متد onLowMemory برای جلوگیری از کرش کمبود حافظه

مرتضی مرادی  9 سال پیش  9 سال پیش
+3 0

در کلاس Application یا همون .G متدی به نام onlowMemory وجود داره که طبق گفته گوگل :

 This is called when the overall system is running low on memory, and actively running processes
should trim their memory usage. While the exact point at which this will be called is not defined,
generally it will happen when all background process have been killed. That is, before reaching the
point of killing processes hosting service and foreground UI that we would like to avoid killing.You
should implement this method to release any caches or other unnecessary resources you may be
holding on to. The system will perform a garbage collection for you after returning from this
method.Preferably, you should implement onTrimMemory(int) from ComponentCallbacks2 to incrementally
unload your resources based on various levels of memory demands. That API is available for API
level 14 and higher, so you should only use this onLowMemory() method as a fallback for older
versions, which can be treated the same as onTrimMemory(int) with the TRIM_MEMORY_COMPLETE level.

 

سوال من اینکه که در زمان اجرای این متد باید چه چیزی رو فراخوانی کنیم تا تمام پروسس های اضافی رو kill کنه و نزاره برنامه کرش کنه ؟ ایا پاک کردن cache برنامه کافیه؟

+1 0
بنظر من اصلا داشتن کلاس Application نسبتا یه چیز غلطیه چون حافظه اشغال میکنه همیشه. اما شما اگه با مشکل کمبود حافظه روبرو هستید، بهتره که حافظه ی هیپ اپ رو افزایش بدید (9 سال پیش)
+1 0
بله همون طور که گفتن دستور زیر رو به manifest.xml اضافه کنین این جوری تا حد زیادی هندل میشه براتون . android:largeHeap="true" (9 سال پیش)
 برای این سوال پاسخی وجود ندارد.

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .