Skip to main content
gamedev.net
🔒 Locked

[java] DUMPING MEMORY!!!!

Started by role Dec 14, 2002 at 5:02 AM 2 replies 300+ views
Original Post
role
role
hi everyone i get an java.lang error about outofmemory i make a very huge image (2500x2500) again and again like this: Image image = createImage(2500,2500); Graphics gfx = image.getGraphics(); image = createImage(2500,2500); image = createImage(2500,2500); // generates an error how can i release the memory before i make a new one?? i try to use image.dispose() but it can''t (no method like that!) also image.flush() // nothing happen then i try to run garbage collector before create a new one, getRuntime().gc() still not work is there a way to dump memory? the problem goes same with this one: (out of memory) int[][] veryHuge = new int[2000][2000]; // then i made more veryHuge = new int[2000][2000] // how to dump the first veryHuge?? oh yeah, i made very big image for making map editor thanx this is very important to me Best Regards,
HenryApe
HenryApe
quote:
image = createImage(2500,2500);

image = createImage(2500,2500); // generates an error


Set the image field to null before the second image creation, that should allow the garbage collector to deallocate the first image object. Setting the veryHuge field to null before the second array creation should also work for your second example.

Which Java version are you using? One would think some JVMs should be able to handle this internally...
role
role
wow!!!
thanx a lot man!!

it works!!! u save me!!

i use JDK 1.4.1
how could i never think bout that!??
by the way, why i got that error!?!
i see my task manager, i still have much free memory,
it is indeed that the image creation takes up to 70,000 K
but i still have 400,000 K free memory!!
so why it generates an error!? i don''t get it!?

anyway, still about memory
which is good between this:

public class Test {
int[][] map;
public void setMap() {
map = new int[100][100];
}
in here i only make one Test instance( Test a = new Test() ), then use setMap to set map variable( a.setMap() )

or :

public class Test {
public Test() {
int[][] map = new int[100][100];
}
}
i must make Test instance everytime to setting map variable
( Test a = new Test() )

the main class like this:

public class Engine {
//Test a;
public Engine() {
//a = new Test();
}
public void setMap() {
Test a = new Test();
//a.setMap();
}
}


thank you very much man!!!

Best Regards,
joanusdmentia
joanusdmentia
i could be wrong but i''d say theres a setting somewhere for the JVM that specifies how much memory it''s allowed to use, so even though you''ve got 400MB free the JVM might only be limited to using 100MB

at a guess, anyway....
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The nly verdict is vengeance; a vendett o

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.