I am working on a Swing based java application. And my application will holds lots and lots of object in the memory and which leads to "Out Of Memory" error. I knew that my code broken somewhere and not handled the memory leaks.
When i was profiling my application, for a study, i have written a thread which will call System.gc() in a specific interval (example: for every 3 minutes) which was reducing the JVM used memory dramatically. I do understand that, the code was not written properly to clear the references of unused objects which giving this behavior.
I am looking into such memory leaks in my code, but still i am having two questions,
- can i write such a thread which request for garbage collection? will it harm my application? i do accept, the performance will be reduced but its not worse than getting out of memory error. 
- Instead of creating a thread, is there any start-up command-line argument which will request for garbage collection for the given specific time interval. 
Thanks in advance !!!
 
     
     
    