←Older revision | Revision as of 05:45, 26 March 2022 | ||
Line 26: | Line 26: | ||
</source> | </source> | ||
- | How this can work? The strings in the constant pool are interned by the [[Java]] virtual machine. ''interned'' strings are kept in some sort of HashMap and can be garbage collected. But only if nobody has reference to them. Especially if their defining class is unloaded from memory. | + | How this can work? The strings in the constant pool are interned by the [[Java]] virtual machine. ''interned'' strings are kept in some sort of HashMap and can be [[Garbage Collection|garbage collected]]. But only if nobody has reference to them. Especially if their defining class is unloaded from memory. |
- | The test first loads the [[API]] class and its strings into memory. Then it constructs interned string ''Hello'' and tries to garbage collected it. In the first case, this succeeds. The first version of the library does not define such string. In the second case the string cannot be garbage collected, as the same ''interned'' object is referenced from the [[API]] class. | + | The test first loads the [[API]] class and its strings into memory. Then it constructs interned string ''Hello'' and tries to [[Garbage Collection|garbage collected]] it. In the first case, this succeeds. The first version of the library does not define such string. In the second case the string cannot be [[Garbage Collection|garbage collected]], as the same ''interned'' object is referenced from the [[API]] class. |
Is this an [[API]]? Technically speaking yes. It is externally observable behaviour. Yet it seems to be that for all practical purposes it is useless to treat this as an [[API]]. It may be useful in some [[HPAPIFest09|extreme API fest game]], yet I'd rather seen this as forbidden use of [[HPAPIFest09|API hack]]. | Is this an [[API]]? Technically speaking yes. It is externally observable behaviour. Yet it seems to be that for all practical purposes it is useless to treat this as an [[API]]. It may be useful in some [[HPAPIFest09|extreme API fest game]], yet I'd rather seen this as forbidden use of [[HPAPIFest09|API hack]]. |