|
Eli, Another thing is to make sure to always "release" large resources as soon as possible and always before reassigning a new allocation to it. For instance if you had something like this: It really should be written as:myResource = new LargeResource(); .... myResource = new LargeResource(); Hope this helps:myResource = new LargeResource(); ... myResource = null; // let the garbage collector cleanup myResource = new LargeResource(); Michael P.S. You can easily test this for yourself with a simple class. First, find a number for the array that just causes the array allocation to fail. On my Sun with Java 1.4.2 it was around 7500000 (7400000 did not fail) with the default memory model. Then uncomment the preceding array = null; assignment and notice that it will not run out of memory. The reason is that array does not become a candidate for garbage collection until after the allocation and assignment unless you first assign it to null. This is not a problem for small classes but for bit ones it is really critical. public class Testit
{
private int[] array;
public Testit()
{
array = null;
}
public void doit()
{
// array = null;
array = new int[7300000];
}
static public void main(String[] args)
{
Testit testit = new Testit();
testit.doit();
testit.doit();
}
}
Dmitri Trembovetski wrote:
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
|
- [JAVA2D] Stumped on WEIRD swing/2d error Rosenstrauch, David
- Re: [JAVA2D] Stumped on WEIRD swing/2d error Igor Nekrestyanov
- Re: [JAVA2D] Stumped on WEIRD swing/2d error Phil Race
- Re: [JAVA2D] Stumped on WEIRD swing/2d error Rosenstrauch, David
- [JAVA2D] Graphics2D.drawImage(Image, AffineTr... eli curtz
- Re: [JAVA2D] Graphics2D.drawImage(Image, ... Dmitri Trembovetski
- Re: [JAVA2D] Graphics2D.drawImage(Ima... Michael Saunders
- Re: [JAVA2D] Graphics2D.drawImage(Ima... eli curtz
- Re: [JAVA2D] Graphics2D.drawImag... Jim Graham
- Re: [JAVA2D] Graphics2D.draw... eli curtz
- Re: [JAVA2D] Stumped on WEIRD swing/2d error Doug Felt
- Re: [JAVA2D] Stumped on WEIRD swing/2d error Rosenstrauch, David
