I have a utility that I built, and for being such a small purpose-built utility I was very surprised when I noticed during testing that it was using 150mb of memory. I ran it with a heap setting of 1MB and it still took up more than 50mb.
After profiling and spending a day trying to figure out where I went wrong, I decided to test a theory. My utility connects to a proprietary application. That connection requires an external library provided by the application vendor.
I wrote a small Hello World using the library and noticed the following:
1) declaring a new object from the vendors library immediately bumps the memory usage to 50MB (mostly permgen space)
2) actually trying to connect to an application server will bump the memory usage to 150MB.
That’s just plain silly as far as I’m concerned.
I’m wondering if there is any potential way to tame the beast. Maybe somehow unload classes that I know aren’t necessary or won’t ever be referenced. The vendor isn’t going to change things any time soon.
Or what about maybe loading the vendor’s library only when necessary? That way it only eats up so much memory while communicating with the app server.
The JVM only loads classes you actually use. In fact it only load methods you actually use. e.g. if you have a byte code bug in a method you don’t use, you won’t know. 😉
The best way to reduce the size of the vendors library is to ask them to improve it, or write your own.
Unfortunately allot of propriety application are not very resource friendly. Their first priority is correctness. :j
BTW: 150 MB of memory costs about $6 so I wouldn’t spend allot more than that much time trying to fix it.