views:

115

answers:

1

how are static method calls handled by the JVM? does it still allocate memory when a call is made? if yes, how does garbage collection treat this allocation after the method call?

+2  A: 

What do you mean by allocate memory? Does it add a stack frame? yes of course, to run the method and allocate local variable storage. Static methods are no different. In fact they're identical except instance methods are invisibly passed this in the method call, behind the scenes.

Any objects that were allocated in the method, and are no longer reachable after the method terminates (perhaps because they were only referred to by a local reference, local to the method) become eligible for GC immediately. There are no guarantees as to when the GC will run though.

But again that's no different for static methods than for any other.

Sean Owen