How to release memory in android to avoid memory leak

Shakeeb Ayaz

While going through the android developer site i found this it says to avoid memory leak we should release resources  in onStop().

it says to avoid memory leak we should release resources in onStop()but how to do so.

Kai

Basically any objects that are properly nulled are considered released and their memory can be reclaimed by the OS. Your question is too general and it's hard to offer a exhaustive list of methods, but you should generally be aware of these:

  1. Stop/close any services/files/connections that you no longer need
  2. Do NOT store any Drawable in any static Object, Drawables hold references to their owner View's which hold references to their owner Activity's, so if you hold on to any Drawable you will hold onto a lot of objects/memory unnecessarily
  3. For an utility app, you probably needn't worry about memory; but for apps that use lots of Bitmaps, you should have a deep understanding of Bitmap management and how Bitmaps are used in your app in order to manage them effectively

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to avoid this memory leak?

From Dev

Avoid memory leak with WeakReference Android

From Dev

How to release memory in Android?

From Dev

Avoid Memory leak

From Dev

How to avoid a memory leak with __block and completion blocks

From Dev

how to avoid memory leak in dynamically allocated widget

From Dev

How can I fix to avoid a memory leak?

From Dev

How can I avoid a memory leak in this function?

From Dev

How to avoid a memory leak with __block and completion blocks

From Dev

Weak reference instead of getActivity() (Android avoid memory leak)?

From Dev

Android animations memory leak

From Dev

Is it a memory leak in android

From Dev

memory leak with Android WebView

From Dev

Is it a memory leak in android

From Dev

Android - is this a memory leak?

From Dev

Prevent memory leak in Android

From Dev

How to avoid memory leak with shared_ptr and SWIG

From Dev

How to avoid memory leak at design-implementation level

From Dev

Node and RxJs: How can I avoid a memory leak on a long process?

From Dev

How to avoid a memory leak by using pthread_cancel?

From Dev

Node and RxJs: How can I avoid a memory leak on a long process?

From Dev

How to handle unmounting a component with set interval to avoid a memory leak

From Dev

How to block this memory leak?

From Dev

How to detect a memory leak?

From Dev

Node.js: How to release Mongoose model from memory? (memory leak)

From Dev

HDC memory leak (release HDC/ delete hdc)

From Dev

nodejs setMaxListeners to avoid memory leak detection

From Dev

Ways to avoid memory leak when exception thrown

From Dev

weak to non class types to avoid memory leak

Related Related

HotTag

Archive