Java running out of memory...

GravHits

  • *
  • Posts: 7
I know this is a relatively common issue but I have yet to find a cause, let alone a solution!
I find myself constantly battling "90% memory" warnings and "out of memory" messages when i work in stencyl, especially when dealing with backgrounds. I'm presently working on a space shooter so my background is literally a black scene with a background layer containing a handful of scattered white pixels representing stars. This background layer contains about 8 frames simulating the twinkle of stars by using more or less opacity... that's it! How on earth does that consume 4gb+ of memory!? Also, the forum posts regarding raising the available memory for the java virtual machine are not very clear... isn't there (shouldn't there be) an option inside of stencyl itself to manage that!?
Thanks for any help possible! 
Mitch

rob1221

  • *
  • Posts: 9459
An image still takes up memory based on its size even if over 90% of it is a single color.  I'm not sure how it's handled on the Java side, but a 640x480 image is 307,200 pixels.  If a pixel takes up 4 bytes and you have 8 frames, then the final number is far too large for Java to easily handle even if you did raise the memory a bit.

Just set the scene color to black and use actors for the stars.

GravHits

  • *
  • Posts: 7
That's a reasonable alternative thanks! But how does one include more complex backgrounds? :-\
(and just to clarify, my background frames are empty (not black) but contains a handfull of white dots. the black comes from the scene color)

rob1221

  • *
  • Posts: 9459
Transparent space still takes up memory.  Having a screen-sized multi-frame animation is not really a good idea whether it's done with backgrounds, actors, images, etc.  That is especially true on mobile where the 4x version of the animation uses 16x the already large memory.