首页 > Can using too many static variables cause a memory leak in Java?

Can using too many static variables cause a memory leak in Java?

If my application has too many static variables or methods, then as per definition they will be stored in heap. Please correct me if I am wrong
1) Will these variables be on heap until application is closed?
2) Will they be available for GC at any time? If not can I say it is a memory leak?


1) yes. if they are reference type, they will be stored in heap.
2) no, but if their classloaders are collected, may be they are. memory leak? that depends on you.

【热门文章】
【热门文章】