Java interfaces... Dynamic or static memory?
Where do java interfaces reside in memory? Do they reside in the heap or the stack, or ma开发者_StackOverflow社区ybe global memory? I am thinking the are in the stack since they are created at compile time. Am I correct?
Class definitions -- including interfaces and abstract classes -- are held in PermGen space, meaning they are never garbage collected. The PermGen is, iirc, a part of the heap.
Interfaces are technically not "instantiated" in the sense that a regular class instance is created, but class information is stored in the java permgen space. See http://blogs.oracle.com/jonthecollector/entry/presenting_the_permanent_generation for more information on the permgen and the difference between a class instance and class information.
Class definitions (including interfaces, etc) are stored on the heap (usually in the Permanent generation because their lifetime is long). If the ClassLoader
that created them is garbage collected, they too are then eligible for garbage collection.
精彩评论