JAXB Context rule for memory leak


(Jiri Stary) #1

When new instance of JAXBContext is created, it creates a small memory leak.
It is a bad bractice to create a new instance every time xml is read.

JaxbContext jaxbContext = JAXBContext.newInstance(clazz);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

Instead jaxbContext should be created only once - for example as static variable


(Alexandre Gigleux) #4

Hello Jiri,

I’m afraid that if we simply raise an issue on each JAXBContext.newInstance call, we will raise a lot of FPs.

Could you be more precise about what you would consider as a bad way to declare a JAXBContext? … and a good way to declare it?

Thanks