How can I create a memory leak in Java?

后端 未结 30 2225
没有蜡笔的小新
没有蜡笔的小新 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:54

    Everyone always forgets the native code route. Here's a simple formula for a leak:

    1. Declare native method.
    2. In native method, call malloc. Don't call free.
    3. Call the native method.

    Remember, memory allocations in native code come from the JVM heap.

提交回复
热议问题