Why do I get an OutOfMemoryError when inserting 50,000 objects into HashMap?

前端 未结 10 1934
猫巷女王i
猫巷女王i 2021-02-01 08:12

I am trying to insert about 50,000 objects (and therefore 50,000 keys) into a java.util.HashMap. However, I keep getting an OutOfMemo

10条回答
  •  独厮守ぢ
    2021-02-01 08:51

    The Java heap space is limited by default, but that still sounds extreme (though how big are your 50000 segments?)

    I am suspecting that you have some other problem, like the arrays in the set growing too big because everything gets assigned into the same "slot" (also affects performance, of course). However, that seems unlikely if your points are uniformly distributed.

    I'm wondering though why you're using a HashMap rather than a TreeMap? Even though points are two dimensional, you could subclass them with a compare function and then do log(n) lookups.

提交回复
热议问题