So you just wrote this awesome application and made it multi-threaded for performance reasons. However, now when you run it after a while you get an out of memory exception. You go and check your system ram and the application isn't even using up half of it yet. What gives?
The problem resides with the heap that garbage collection uses and the way that garbage collection works. I won't go into details here about that however I will offer some possible solutions. There are 2 types of garbage collection, workstation and server. Workstation gives you one process and one heap to manage for the entire application regardless of the number of threads. Server will setup a new Garbage Collection thread and heap for each thread launched. Thus this should allow you to avoid that pesky out of memory issue.
Be carefull however, if you are launching hundreds of threads or maybe even more it may be possible for you to run out of ram. To avoid this do a poll of the current state of your ram before launching a new thread as well as try setting a max number of threads you will launch based off of the ammount of ram on the machine.
Please check out more articles at http://techtify.blogspot.com
Feedback/Questions
If you have any topics you would like me to cover or just general feedback on blogs I have written feel free to email me at helloriker@hotmail.com.
Thursday, September 17, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment