How to reproduce Java OutOfMemoryError - GC overhead limit exceeded

前端 未结 3 1119
天涯浪人
天涯浪人 2020-12-29 07:30

My approach was to create hundred thousand local collections and populate them with random strings, something like this:

    SecureRandom random = new Secure         


        
3条回答
  •  暖寄归人
    2020-12-29 08:04

    This:

    HashMap map = new HashMap();
    

    is scoped within the loop and there are no external (long-term) references to the map created as the loop iterates. Hence each map will be eligible for garbage collection at the end of each loop iteration.

    You need to create a collection of objects outside the loop, and use the loop to populate that collection.

提交回复
热议问题