Re: Memory Leak
I've run FindBugs (http://findbugs.sourceforge.net/) on Forge SVN source code and some intresting things came out
example:
Concatenation strings using + in a loop. This brings a lot of grabage on stack and later to gc. Use StringBuilder.
Three's also some null targeting around which if executed most likely will give strange results.
And for the last one, that I really liked (there's way more and not everything is really relevant). It's not your code but from javazoom.jl

One of the reasons to use static code analysis to check for common and easy to fix errors.
I would urge you to at least check FindBugs (integrates fully with Eclipse/Netbeans and other software).
example:
- Code: Select all
(name != null) &&
name.toLowerCase().endsWith(".jpg") ||
name.toLowerCase().endsWith(".jpeg") ||
name.toLowerCase().endsWith(".gif") ||
name.toLowerCase().endsWith(".png")
I suppose you use mostly small numbers for hand, cards in play, etc. And this would bring some speedup.Using new Integer(int) is guaranteed to always result in a new object whereas Integer.valueOf(int) allows caching of values to be done by the compiler, class library, or JVM. Using of cached values avoids object allocation and the code will be faster.
Values between -128 and 127 are guaranteed to have corresponding cached instances and using valueOf is approximately 3.5 times faster than using constructor. For values outside the constant range the performance of both styles is the same.
Concatenation strings using + in a loop. This brings a lot of grabage on stack and later to gc. Use StringBuilder.
Three's also some null targeting around which if executed most likely will give strange results.
And for the last one, that I really liked (there's way more and not everything is really relevant). It's not your code but from javazoom.jl
- Code: Select all
static public Object deserialize(InputStream in, Class cls)
throws IOException
{
if (cls==null)
throw new NullPointerException("cls");
Object obj = deserialize(in, cls);
if (!cls.isInstance(obj))
{
throw new InvalidObjectException("type of deserialized instance not of required class.");
}
return obj;
}
One of the reasons to use static code analysis to check for common and easy to fix errors.
I would urge you to at least check FindBugs (integrates fully with Eclipse/Netbeans and other software).