Author Topic: ERROR/dalvikvm-heap(6950): Out of memory on a 1048592-byte a  (Read 20547 times)

Offline buiminhhuy

  • byte
  • *
  • Posts: 9
    • View Profile
ERROR/dalvikvm-heap(6950): Out of memory on a 1048592-byte a
« on: January 29, 2011, 06:45:24 am »
Quote
01-29 12:28:34.558: ERROR/dalvikvm-heap(6950): Out of memory on a 1048592-byte allocation.
01-29 12:28:34.558: INFO/dalvikvm(6950): "GLThread 12" prio=5 tid=9 RUNNABLE
01-29 12:28:34.558: INFO/dalvikvm(6950):   | group="main" sCount=0 dsCount=0 s=N obj=0x460069c0 self=0x37e000
01-29 12:28:34.558: INFO/dalvikvm(6950):   | sysTid=6972 nice=0 sched=0/0 cgrp=default handle=3409408
01-29 12:28:34.558: INFO/dalvikvm(6950):   | schedstat=( 33403747505 41698944175 45115 )
01-29 12:28:34.558: INFO/dalvikvm(6950):   at com.threed.jpct.Texture.loadTexture(Texture.java:~754)
01-29 12:28:34.558: INFO/dalvikvm(6950):   at com.threed.jpct.Texture.loadTexture(Texture.java:667)
01-29 12:28:34.558: INFO/dalvikvm(6950):   at com.threed.jpct.Texture.<init>(Texture.java:175)
01-29 12:28:34.558: INFO/dalvikvm(6950):   at com.splendor.app.directions.ar.ARDirectionsRenderer.onDrawFrame(ARDirectionsRenderer.java:99)
01-29 12:28:34.558: INFO/dalvikvm(6950):   at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1341)
01-29 12:28:34.558: INFO/dalvikvm(6950):   at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
01-29 12:28:34.558: ERROR/dalvikvm(6950): Out of memory: Heap Size=16647KB, Allocated=13817KB, Bitmap Size=7275KB

Group heap is always increase
Quote
01-29 12:28:04.758: INFO/jPCT-AE(6950): Loading Texture...
01-29 12:28:04.758: INFO/jPCT-AE(6950): [ 1296278884762 ] - WARNING: Unsupported Texture width (1000)...resizing to 512...
01-29 12:28:04.898: INFO/dalvikvm-heap(6950): Grow heap (frag case) to 19.895MB for 1048592-byte allocation

01-29 12:28:31.688: INFO/jPCT-AE(6950): Loading Texture...
01-29 12:28:31.688: INFO/jPCT-AE(6950): [ 1296278911692 ] - WARNING: Unsupported Texture width (1000)...resizing to 512...
01-29 12:28:32.168: INFO/dalvikvm-heap(6950): Grow heap (frag case) to 20.895MB for 1048592-byte allocation

although I have freed memory of bimap in my snip my code
Quote
@Override
   public void onDrawFrame(GL10 arg0) {
      try {
         if (!stop) {   
            setCameraOrientation(mOrientationValue);
            if(mSteps!=null){
               List<GeoLocation> lsGeo=checkSteps(mSteps, mCurloc, IMG_WIDTH);
               Drawable streets;
               streets= new StreetsDrawable(lsGeo);               
               Bitmap bitmap = Bitmap.createBitmap(IMG_WIDTH,
                       IMG_HEIGHT, Bitmap.Config.ARGB_8888);
                 Canvas c = new Canvas(bitmap);
                 streets.draw(c);
                 Texture streetsTexture = null;
                 streetsTexture = new Texture(bitmap);
                 streetsTexture.setMipmap(true);
                 if (bitmap != null) {   
                     bitmap.recycle();       
                     bitmap = null;   
                     System.gc();
                      }
                 if(tm.containsTexture("streets")){
                    tm.removeTexture("streets");
                 }
               tm.addTexture("streets",streetsTexture);
               c=null;
               streetsTexture=null;
               System.gc();
               
               streets=null;
               mSteps=null;
               lsGeo=null;
            }
            
            fb.clear(back);
            world.renderScene(fb);
            world.draw(fb);
            
            fb.display();

         } else {
            if (fb != null) {
               fb.dispose();
               fb = null;
            }
         }
      } catch (Exception e) {
         Logger.log(e, Logger.MESSAGE);
      }

   }

Why is Memory always increase? Can you help me?
Thanks for Avandce!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: ERROR/dalvikvm-heap(6950): Out of memory on a 1048592-byte a
« Reply #1 on: January 29, 2011, 10:42:51 am »
All your textures seem to be in non-power-of-2-formats with 1000*something. This increases memory usage at load time because it forces a rescale on each loading. Try to scale them down to 512*512 instead before loading them. The automatic rescale has been removed from latest version anyway. How many textures are you using? Keep in mind that Dalvik's memory is pretty limited.

Offline buiminhhuy

  • byte
  • *
  • Posts: 9
    • View Profile
Re: ERROR/dalvikvm-heap(6950): Out of memory on a 1048592-byte a
« Reply #2 on: January 29, 2011, 07:25:39 pm »
I try use image import on texture with size 250x250, problem Group heap is always increase not happen.
However Load Texture is always WARNING.
Quote
01-30 01:17:43.201: INFO/jPCT-AE(12715): Loading Texture...
01-30 01:17:43.201: INFO/jPCT-AE(12715): [ 1296325063209 ] - WARNING: Unsupported Texture width (250)...resizing to 128...

My aplication is alway draw invalidate streets image(base on Location GPS calculated my scale) in OnDrawFrame every time Location Provider Change.

Thanks Sir for helped me.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: ERROR/dalvikvm-heap(6950): Out of memory on a 1048592-byte a
« Reply #3 on: January 29, 2011, 11:17:25 pm »
250 is NO power of 2. Using this size will fail on any newer version of jPCT-AE.
« Last Edit: January 29, 2011, 11:34:06 pm by EgonOlsen »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: ERROR/dalvikvm-heap(6950): Out of memory on a 1048592-byte a
« Reply #4 on: January 29, 2011, 11:25:23 pm »
Btw: If want to replace a texture in the manager with another one using the same name, simply use the replace-method. What you are doing causes copies of the textures Being left in gpu memory and objects that use the texture "streets" will be painted all white after that. They don't get the information that their texture had changed this way. I think we recently had another thread dealing with this too.
« Last Edit: January 29, 2011, 11:27:52 pm by EgonOlsen »

Offline buiminhhuy

  • byte
  • *
  • Posts: 9
    • View Profile
Re: ERROR/dalvikvm-heap(6950): Out of memory on a 1048592-byte a
« Reply #5 on: January 30, 2011, 08:11:46 am »
Quote
Drawable streets;
                  streets= new StreetsDrawable(lsGeo);               
                  Bitmap bitmap = Bitmap.createBitmap(IMG_WIDTH,
                          IMG_HEIGHT, Bitmap.Config.ARGB_8888);
                    Canvas c = new Canvas(bitmap);
                    streets.draw(c);
                    Texture streetsTexture = null;
                    streetsTexture = new Texture(bitmap);
                    streetsTexture.setMipmap(true);
                    if (bitmap != null) {    
                                 bitmap.recycle();        
                                 bitmap = null;    
                                 System.gc();
                              }
                    if(tm.containsTexture("streets")){
                       tm.removeAndUnload("streets",fb);
                       tm.replaceTexture("streets",streetsTexture);
                    }else{
                       tm.addTexture("streets", streetsTexture);
                    }                  
               

I have been use above snip code, and resize image 250x250. However sometime get error below
Quote
Grow heap (frag case) to xxxxMB for xxxx-byte allocation
xxxx is number memory  increase than every time draw invalidate streets.
Current, i only use this solution(draw image: paint streets of the real world into image based on address GPS Location).But get problem about memory. I can not resize image smaller, because it had been picture not clearly.(if Solution any can, i hoped that it could keep size of image is 500x500, if 1000x1000 that is good.)

Thanks Sir.

P/S: I do not know to make any way to resolve the problem memory. Please! help me?.
« Last Edit: January 30, 2011, 08:18:43 am by buiminhhuy »

Offline Kaiidyn

  • long
  • ***
  • Posts: 103
    • View Profile
Re: ERROR/dalvikvm-heap(6950): Out of memory on a 1048592-byte a
« Reply #6 on: January 30, 2011, 10:17:10 am »
try resizing your textures to 256 manually.
Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer’s intent but rather is full of crisp abstractions and straightforward lines of control. - Grady Booch

Offline buiminhhuy

  • byte
  • *
  • Posts: 9
    • View Profile
Re: ERROR/dalvikvm-heap(6950): Out of memory on a 1048592-byte a
« Reply #7 on: January 30, 2011, 12:04:04 pm »
i dont see any method of texture in javadoc about resize or setsize of Texture. Can you help me? Thanks.

Offline Kaiidyn

  • long
  • ***
  • Posts: 103
    • View Profile
Re: ERROR/dalvikvm-heap(6950): Out of memory on a 1048592-byte a
« Reply #8 on: January 30, 2011, 02:12:53 pm »
resize your textures manually in a program like photoshop or something :-)
Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer’s intent but rather is full of crisp abstractions and straightforward lines of control. - Grady Booch

Offline buiminhhuy

  • byte
  • *
  • Posts: 9
    • View Profile
Re: ERROR/dalvikvm-heap(6950): Out of memory on a 1048592-byte a
« Reply #9 on: January 30, 2011, 04:33:54 pm »
oh, it is image create dynamic. create runtime


Offline buiminhhuy

  • byte
  • *
  • Posts: 9
    • View Profile
Re: ERROR/dalvikvm-heap(6950): Out of memory on a 1048592-byte a
« Reply #11 on: January 30, 2011, 06:58:45 pm »
Thanks, i have been resolve my problem. No WARNING load texture and No Group heap is always increase.

Thanks  EgonOlsen very much.(sory because not read JavaDoc clearly). Thanks sir this days.
Thanks  Thomas very.

I have bean resolve my problem with snip code below:
Quote
                            Drawable streets;
                  streets= new StreetsDrawable(lsGeo);               
                  Bitmap bitmap = Bitmap.createBitmap(IMG_WIDTH,
                          IMG_HEIGHT, Bitmap.Config.ARGB_8888);
                    Canvas c = new Canvas(bitmap);
                    streets.draw(c);
                                        Texture streetsTexture = null;
                    
Quote
streetsTexture = new Texture(BitmapHelper.rescale(bitmap, 256, 256));   
                 
                    streetsTexture.setMipmap(true);
                    freeBitmap(bitmap);
                    if(tm.containsTexture("streets")){
                       tm.removeAndUnload("streets",fb);
                       tm.replaceTexture("streets",streetsTexture);
                    }else{
                       tm.addTexture("streets", streetsTexture);
                    }                  

Offline buiminhhuy

  • byte
  • *
  • Posts: 9
    • View Profile
Re: ERROR/dalvikvm-heap(6950): Out of memory on a 1048592-byte a
« Reply #12 on: January 30, 2011, 07:53:15 pm »
Quote
01-31 01:49:08.209: INFO/StreetsDrawable(26528): Begin Draw Streets
01-31 01:49:08.219: INFO/StreetsDrawable(26528): 0----0
01-31 01:49:08.219: INFO/StreetsDrawable(26528): -279-----77
01-31 01:49:08.219: INFO/StreetsDrawable(26528): -1161-----222
01-31 01:49:08.219: INFO/StreetsDrawable(26528): The End Draw Streets
01-31 01:49:08.529: INFO/jPCT-AE(26528): Loading Texture...
01-31 01:49:08.569: DEBUG/lib_locapi(4670): loc_eng_report_status: GPS_STATUS_SESSION_BEGIN
01-31 01:49:08.679: DEBUG/dalvikvm(26528): GC_FOR_MALLOC freed 791 objects / 39288 bytes in 154ms
01-31 01:49:08.699: INFO/dalvikvm-heap(26528): Grow heap (frag case) to 21.244MB for 1048592-byte allocation

I can not understand why sometime Grow heap is increase when draw street, sometime  Grow heap is not increase . although I have been free memory of bimap and manager texture the same than every time draw street.

Offline buiminhhuy

  • byte
  • *
  • Posts: 9
    • View Profile
Re: ERROR/dalvikvm-heap(6950): Out of memory on a 1048592-byte a
« Reply #13 on: January 30, 2011, 08:26:42 pm »
i think i will use OpenGlES for draw street of me. Because Texture i can not free memory.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: ERROR/dalvikvm-heap(6950): Out of memory on a 1048592-byte a
« Reply #14 on: January 30, 2011, 09:01:07 pm »
After all, you can't control the garbage collector. You simply don't know when and why it collects garbage or not. System.gc(); doesn't enforce this by definition. It's just a hint. However, are you still getting OutOfMemory-Exceptions or are you just bothering with that heap-increase-message? I wrote myself a little test case that does this in each frame:

Code: [Select]
cnt++;
if ((cnt & 2) == 0) {
Texture t=new Texture(1024, 1024, new RGBColor(cnt % 255, cnt % 255, cnt % 255));
t.setMipmap(true);
TextureManager.getInstance().unloadTexture(fb, TextureManager.getInstance().getTexture("texture"));
TextureManager.getInstance().replaceTexture("texture", t);
Logger.log("new Texture!");
}

I.e. every second frame, it creates a new 4 MB large texture and replaces the former one with it. This runs without problems, the memory will be reclaimed as needed. However, i get a log message each time i'm doing this:

Code: [Select]
01-30 19:55:04.288: INFO/dalvikvm-heap(491): Grow heap (frag case) to 14.706MB for 4194320-byte allocation

...with exactly the same value of 14.706MB over and over again. So the VM prints out BS here IMHO, but it doesn't hurt. I don't see why it shouldn't work in your case unless the rest of what you are doing (canvas, drawable, bitmap...) is causing a problem somehow. I've read multiple times that working with Bitmap can cause memory leaks for example.