开发者

android java memory management

开发者 https://www.devze.com 2022-12-28 21:19 出处:网络
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 allo开发者_JAVA技巧cation after the method call?What d

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 allo开发者_JAVA技巧cation after the method call?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消