LoginSignup
30
31

More than 5 years have passed since last update.

AndroidでのOutOfMemory対策

Last updated at Posted at 2014-10-29

OutOfMemory対策

Android端末のMemoryはまだまだ小さく、heapの割り当ても少ないので、
OutOfMemory対策として、地道な作業をコツコツとやってみました。
昔のJavaのGC対策のようなものです。

まずは現状を知る

EclipseのMemoryAnalyzerなどで、heapdumpを見てみる。
どこでMemoryを使っているか確認してみてください。

各種clean方法

ImageView

特に重くなっていくImageview

imageview
imageView.setImageDrawable(null); or imageView.setImageBitmap(null);
imageView.destroyDrawingCache();

Loader

止め忘れ防止として

Loader
getSupportLoaderManager().destroyLoader(loder id)

Animation

cancel()も調べては見ましたが、実装見るとresetの方が良さそう

Animation

Animation.reset();

Adapter(ArrayAdapter)

Adapter

Adapter.clear();
Adapter.notifyDataSetChanged();

各メンバ変数

nullをぶち込む


まだまだ他にもやるべき所や、間違っている部分あるかも知れません。
自分のアプリではある程度の安定は見られました。
基本的に、使いまわせるObjectは使いまわして、call側から設定してあげる
などの配慮をすると、AnimationやUIもカクカクしなくなったりします。

30
31
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
31