How can I create a memory leak in Java?

后端 未结 30 1805
没有蜡笔的小新
没有蜡笔的小新 2020-11-21 22:26

I just had an interview, and I was asked to create a memory leak with Java.

Needless to say, I felt pretty dumb having no clue on how to eve

30条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-21 22:43

    Maybe by using external native code through JNI?

    With pure Java, it is almost impossible.

    But that is about a "standard" type of memory leak, when you cannot access the memory anymore, but it is still owned by the application. You can instead keep references to unused objects, or open streams without closing them afterwards.

提交回复
热议问题