[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] memory leak when using caches?
|
Hello Chris,
The "eclipselink.maintain-cache" hint that you mentioned seems interesting.
Assume running a query that has got that hint and returns an object o, upon others.
Can you tell me, what's the bevaviour of EL, when I call "em.find (ClassOfObjectO.class, o.getID());"?
Does it execute another query to get o into the cache?
Best Regards,
Michael
-----Ursprüngliche Nachricht-----
Von: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] Im Auftrag von Christopher Delahunt
Gesendet: Freitag, 30. September 2011 21:49
An: EclipseLink User Discussions
Betreff: Re: [eclipselink-users] memory leak when using caches?
It depends.
If you load an infinite amount of objects in memory, you will eventually
run out of memory at a certain point if you are keeping references to
those objects. As long as you are reference objects, they cannot be
collected by the garbage collector. It maybe that adding memory to the
JVM; for instance if you need to bring in the entire database into the
application.
The EntityManager though is required to keep references to managed
entities. Detached is what is meant when the entityManager does not have
a reference to the entity itself (though with serialization of the
entity, it still has its own copy of that entity). Calling clear
detaches references by removing the EntityManager's links to those
Entities - they are free to for garbage collection as long as the
application is also not referencing them.
The wikibooks topic describing clear might be useful to you:
http://en.wikibooks.org/wiki/Java_Persistence/Persisting#Clear
The dontMaintainCache() option on the ReadQuery is related to the
eclipselink.maintain-cache query hint described here:
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Query_Hints#Maintain_Cache.
It will return detached entities that you will need to merge into the
EntityManager should you need to make changes.
You might want to read the EclipseLink docs on caching found here:
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Caching
Why are you loading in hundreds of thousands of objects in a single
EM/transaction? Can you read and process it in batches, and clear the EM
after each batch so the objects can be released?
Best Regards,
Chris
On 30/09/2011 2:40 PM, Michael Pflueger wrote:
> Hi,
>
> when reading lots(hundreds of thousands) of objects from a table (within a single entity manager/transaction), I seem to get memory leaks (heap usage is growing to 250MB/MAX quickly and soon thereafter I get an OutOfMemory Error).
> This happens even when I set eclipselink.cache.type.default to NONE in my persistence.xml.
>
> What does help is either using raq.dontMaintainCache(); on the query, or repeatedly calling em.clear(); on the entity manager. Can anybody explain this behavior?
> I already had this problem with openjpa and it is somewhat annoying to see outofmemory errors here again :)
>
> Regards,
> Michael
> ___________________________________________________
>
> SMA Solar Technology AG
> Aufsichtsrat: Guenther Cramer (Vorsitzender)
> Vorstand: Juergen Dolle, Roland Grebe, Uwe Hertel, Pierre-Pascal Urbon, Marko Werner
> Handelsregister: Amtsgericht Kassel HRB 3972
> Sitz der Gesellschaft: 34266 Niestetal
> USt-ID-Nr. DE 113 08 59 54
> WEEE-Reg.-Nr. DE 95881150
> ___________________________________________________
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users