So I have an application that allows you to upload documents and images and saves these as byte[] in the database.
(I created an minimal example project that you can download as zip here and import into STS http://dl.dropbox.com/u/2342474/byteMemoryLeak.zip... all you have todo is go to the datasource.groovy and change your db settings)
So the domain object looks something like this:
class Test {
byte[] data
static constraints = {
data nullable: false, maxSize: 1024*1024*40
}
}
and the controller and views are all generated directly with the generate-all command... nothing changed here...
So now when we start the project we go to the test controller... hit create new... upload a document ... use something thats like 5 - 10 mb... and hit create...
I expect the memory usage to go up while the save() method is execute and then when the show method is called too... but once those are finished loading GC should pick up those objects and throw them away since they are currently not needed... now i used Your Kit Java Profiler to check the memory usage and i can see that there are 3 reference of my byte[] which have weak reference or are unreachable... why is that? shouldnt they have been removed right when the show() method or save() method complete?
Here a screenshot: [memory leak]: https://i.stack.imgur.com/R7KMt.png
Do I have to make special settings for tomcat to run the gc more often?
I am very confused about this and it actually causes a problem in the application that I have in testing right now cause people are uploading a lot of documents to it and the heap memory just gets fuller and fuller and gets almost never cleaned so that i get at some point an out of memory exception... the same actually happens also in the list() method that it loads all the objects and now actually for each object the byte[] is loaded and now in memory and doesnt get cleaned up...
Maybe I am just missing something or doing something wrong... any help would be greatly appreciated...
Thanks Chris