One of our service has a function written with Java.
And some loop call this function many times.
Unfortunately that service sometimes crashed by memory leak.
So I reviewed the source code and found the memory leak point - already fixed it.
But I am not sure gabage collector activate after java function ended.
The Java function use so many variables with ‘new’ operator, but there were no place to clean up.
Please let me know when is gabage collector called?
After Java fuction is ended? or the service is ended?
PS. Thanks for your reading. this is my first time to ask a question with English.
Hi Ally,
There is no pre definied time or any definit point when GC (garbage collector) will run. Mainly when JVM feels that heap is running out of memory then it executes GC. You can also request JVM to run GC (System.gc())but there is no guarantee that GC will get executed.
You mean that GC run automatically by JVM when heap is running out of memory and don’t recommand to call GC by manually.
I feel that is not reliable or I guessed wrong.
I said fixed memory leak. It was duplicated ‘new’ operation.
for example, class a{…} … a arry = new a[100], arry[0] = new a(), arry[1] = … and other place a[0] = new a(), a[1] = new a()…
I think that those codes caused memory leaks, and this will makes heap is running out of memory. → GC will activate and no crash.
But It was not. T^T
Anyway I will study for these more. I am just a begginer of Java and webMethods.
Thank you for your kindness.