How to deal with memory issues? [SOLVED]
in
Programming Questions
•
7 months ago
Ok, I'm kinda lost (again).
Here's the problem. For each layer of my game that I want to render I use a function that, based on an Arraylist of elements (called 'mundo').
The problem is that when running this specific part of the code my memory usage bumps like 50mb/sec. In 30 secs the game is obviously unplayable.
If it was C++ I would think about pointers. In java/processing I don't know how the memory is handled but I guess I'm filling it with n elements each frame - they are not using the same memory address. I'm I right?
If so, what do you guys suggest?
Trash collecting or something like that (does processing collects garbage)?
Bellow follows the code:
Thank you in advance
void render0()
{
for (i=0; i<mundo.size(); i++)
{
if (mundo.get(i).getZ_index() == 0) //z_index defines the number of the "layer"
{
latlong = oTile.getSprite(mundo.get(i).getType()); //type defines what sprite I should use
image (latlong, pix2unit(mundo.get(i).getX()), pix2unit(mundo.get(i).getY()));
//I assume that for every new frame the image will be erased. Does it leave the memory?
}
}
}
--------------------------------------------------------------------------------------------
//a sample from the switch/case that returns the image:
case 0: //here's where the 'getType' from the render0 will land.
tile = loadImage("imgs/sets/green_dungeon/simple_floor.png");
return tile;
Here's the problem. For each layer of my game that I want to render I use a function that, based on an Arraylist of elements (called 'mundo').
The problem is that when running this specific part of the code my memory usage bumps like 50mb/sec. In 30 secs the game is obviously unplayable.
If it was C++ I would think about pointers. In java/processing I don't know how the memory is handled but I guess I'm filling it with n elements each frame - they are not using the same memory address. I'm I right?
If so, what do you guys suggest?
Trash collecting or something like that (does processing collects garbage)?
Bellow follows the code:
Thank you in advance
void render0()
{
for (i=0; i<mundo.size(); i++)
{
if (mundo.get(i).getZ_index() == 0) //z_index defines the number of the "layer"
{
latlong = oTile.getSprite(mundo.get(i).getType()); //type defines what sprite I should use
image (latlong, pix2unit(mundo.get(i).getX()), pix2unit(mundo.get(i).getY()));
//I assume that for every new frame the image will be erased. Does it leave the memory?
}
}
}
--------------------------------------------------------------------------------------------
//a sample from the switch/case that returns the image:
case 0: //here's where the 'getType' from the render0 will land.
tile = loadImage("imgs/sets/green_dungeon/simple_floor.png");
return tile;
1