tags:

views:

89

answers:

2

I have an application that, in order to reload plugins, requires them with the :reload option whenever they are to be reloaded. I've noticed that this is building up memory about 2-3 megs at a time when I do it. I'm curious as to what could cause this sort of thing to happen. Is data from previous reloads being kept in memory? Is there a way to totally reload a namespace?

EDIT: It's also relevant to mention that each of these plugins that gets reloaded makes new defmethods for a multimethod in another namespace (that never gets reloaded). Maybe the methods are being kept in memory when it's reloaded?

A: 

Clojure defers memory management to the JVM. While I don't know clojure's codebase deeply, it probably just reassigns the vars with the reloaded code - which will leave the old objects around until the JVM runs the garbage collector.

You can hint to the JVM that you want the GC to run using (System/gc), but it's generally not recommended to use.

Alternatively, if you know the contraints of your system, you can tinker with the JVM memory flags to encourage the GC to run more frequently (ie - use a lower heap size).

But if you have a system that's not really memory constrained, saving a few mbs doesn't matter much.

Jeff
+1  A: 

As it turns out, I didn't test it long enough. The memory will only grow to a certain level, and then it'll stop and eventually go back down quite a bit.

Boys and girls: test your code before whining about bugs.

Rayne