0

I have a problem with type List<Map<String, Object>>. I defined a Map<String, Object> variable with which include one item (size = 1) and then a clone of this variable is added in another List. but when I read in the next step, I have a strange problem with the readed item (Map<String, Object>) from the List because the readed variable has a large size, even though the added variable had size 1.

Why is this happening?

List<PlacementElementByHost> Placement_Queue = new LinkedList<>();

while(...){
  PlacementElementByHost first=new PlacementElementByHost(Placement_Queue.get(0));
  Placement_Queue.remove(0);
  PlacementElementByHost new_element=new PlacementElementByHost();
  new_element.migrationMap.add(new HashMap<>(migrate));
  for(...){
  Placement_List.add(new PlacementElementByHost(new_element));
  }
}

and when I want to read:

PlacementElementByHost first=new PlacementElementByHost(Placement_Queue.get(0));
Eypros
  • 5,370
  • 6
  • 42
  • 75
  • 4
    Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – DavidPostill Jul 29 '14 at 11:37
  • Try increasing your vm memory. Java heap space error is not an overflow. The size of the `List` has nothing to do with the size of the `Object` it includes. – Eypros Jul 29 '14 at 11:58
  • possible duplicate of [What is an OutOfMemoryError and how do I debug and fix it](http://stackoverflow.com/questions/24510188/what-is-an-outofmemoryerror-and-how-do-i-debug-and-fix-it) – Raedwald Jul 29 '14 at 12:09
  • Thank you Eypros for your Help, But I know that `first.migrationMap` shouldn't have a large size because the `for` loop executed only 198 times but the added items in `first.migrationMap` are 1341312!. `first.migrationMap` should have only one item (size=1). Even though I tried by increasing my VM memory to 1500m but the result was the same before. – Ali Rahmanian Jul 29 '14 at 12:36
  • I found the problem. The problem comes from a `List` variable which is a parameter in its used function and defined as an **extend** parameter which I added this one in an object and the object added in another `List`. so because of my parameter status(` extends List<...`) there's happening an inconsistency. – Ali Rahmanian Jul 29 '14 at 14:37

0 Answers0