Afternoon all,
I've recently moved from using an old version of Castor (0.9.xxx) to the
new stable 1.1. Mainly as i'd like to use the descriptor caching.
However, after moving to castor 1.1 and creating an
XMLClassDescriptorResolver as per the xml-best-practices webpage,
running my application caused an out of memory expection (heapspace).
So i ran the code under jProfiler and have seen symptoms of a memory
leak (or symptoms of not using the resolver correctly ;-).
It my understanding that when marshalling/unmarshalling, the
XMLClassDescriptorResolver should be caching the descriptors for use in
subsequent operations. Then on the subsequent operation (marshal /
unmarshall) it shouldn't have to create those descriptors again
(assumming the same class/xml complex type is being used).
But what i've seen in jProfiler is that after one run of my code there
have been 3828 XMLFieldDescriptorImpl objects created (triggering
garbage collection a few times doesn't change that number either) then
when i run it again (no restart, just second iteration) it finishes what
it's doing and the count of XMLFieldDescriptorImpl objects is now 7725!
It increases with each iteration, and after 10 iterations is 38901
objects, taking up 3.4 megabytes in memory - after a while this gets so
big it causes the memory exception.
So it looks like it's created new XMLFieldDescriptorImpl for the same
classes and xml complex types i used the first time around.
Has anyone else seen this behaviour before? Am i doing somthing wrong
when creating / using the resolver?
Here's the code i use to contruct a resolver (sorry about the formatting):
private XMLClassDescriptorResolver createResolver(Class clazz){
XMLClassDescriptorResolver cdResolver =
(XMLClassDescriptorResolver)ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML);
cdResolver.setClassLoader(Thread.currentThread().getContextClassLoader());
try {
cdResolver.loadClassDescriptors(clazz.getPackage().toString());
return cdResolver;
} catch (ResolverException e) {
logger.warn(e.getMessage() + ":"+clazz.getPackage().toString(),e);
}
return null;
}
as you can see from the above code i create a resolver for each Class i
marshal/unmarshall and store it for subsequent uses of the same
operation (so i'm not creating a new resolver each time as it might appear)
Thank you for your time
Simon Lord
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email