Reza
Reza

Reputation: 161

byte array (byte[], boolean[]) is keeping most of memory allocation, while there is no usage of byte[] in application

in my application i have 1 activity with a viewPager and 8 fragments inside it plus another View pager inside one of its fragments and 3 services running. my total heap dedicated for images is about 1mb, but when my app starts ( in real device ) i have my heaps grown to 17mb (the base heap before any thing starts is 8mb , so it means 9 mb heap grow) how ever on an emulator i see this heap grown is lesser. after Tracking my heaps, i found out 7 mb of it is dedicated to

byte array (byte[], boolean[])

and 3 mb to

byte array (short[], char[])

while i have absolutely no usage of byte[] in my application, and every time i use for decoding images or etc after im done i have nulled its referrence. and after tracking down with allocation tracker i found out like 360 of total 376 is referenced to this trace :

  at java.lang.Float.valueOf(Float.java:397)    
  at   android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:947) 
  at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:476) 
  at android.animation.ValueAnimator.animationFrame(ValueAnimator.java:1123)    
  at           android.animation.ValueAnimator$AnimationHandler.handleMessage(ValueAnimator.java:630)   
  at android.os.Handler.dispatchMessage(Handler.java:99)    
  at android.os.Looper.loop(Looper.java:137)    
  at android.app.ActivityThread.main(ActivityThread.java:4441)  
  at java.lang.reflect.Method.invokeNative(Native Method)   
  at java.lang.reflect.Method.invoke(Method.java:511)   
  at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)    
 at dalvik.system.NativeStart.main(Native Method)   

sorry for headache , so finally my questions are is 17 mb too much or normal size for heap in application and according to these traces where and what type of data should i search for memory leak ? (context,handler,looper,..)? thanks alot in advance

in Addition i might add , i have 10x of always working Handlers with (Looper.getMainLooper), is this gonna be an issue?

Upvotes: 0

Views: 995

Answers (1)

Simon
Simon

Reputation: 11190

Those byte arrays are actually your Bitmap image data. So this is correct. But you can't just null the Bitmap reference. Call Bitmap.recycle(); first. Remember this data is not freed immediately. A GC has to happen. But do not force the GC in production code. Instead perhaps do System.gc(); in onStop(); of your Activity if BuildConfig.DEBUG is true.

Upvotes: 1

Related Questions