views:

137

answers:

3

Where do java interfaces reside in memory? Do they reside in the heap or the stack, or maybe global memory? I am thinking the are in the stack since they are created at compile time. Am I correct?

+4  A: 

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.

Drew Wills
@Drew Wills: isn't PermGen specific to only Sun VMs?
Webinator
@WizardOfOdds that could be -- it's easy (for me) to forget there's any other sort. PermGen is a part of the generational GC strategy: it refers to the _permanent_ generation. Do other JVMs have generational GC?
Drew Wills
@WizardOfOdds won't any answer to this question be JVM-implementation-specific?
matt b
A: 

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.

Ben Lings
A: 

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.sun.com/jonthecollector/entry/presenting_the_permanent_generation for more information on the permgen and the difference between a class instance and class information.

Ed Griebel