Does declaring many identical anonymous classes waste memory in java?
- by depsypher
I recently ran across the following snippet in an existing codebase I'm working on and added the comment you see there. I know this particular piece of code can be rewritten to be cleaner, but I just wonder if my analysis is correct.
Will java create a new class declaration and store it in perm gen space for every call of this method, or will it know to reuse an existing declaration?
protected List<Object> extractParams(HibernateObjectColumn column, String stringVal) {
// FIXME: could be creating a *lot* of anonymous classes which wastes perm-gen space right?
return new ArrayList<Object>() {
{
add("");
}
};
}