You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Marc Jambert <ma...@vegatechnologies.fr> on 2004/08/06 16:01:43 UTC

[Collections] UNITTEST proving for PB with map serialization

Try the following unit test. On my machine 100 iterations are enough to
break memory.
As reported before, this problem is not specific to LRUMap but also in
LinkedMap. Probelm in AbstractLinkedMap ?






public void testLRUMapSerializationDeserializationMemoryLeak () throws
Exception {
	{
	    // First prove that the test pass with normal HashMap 
	    HashMap map = new HashMap (1000);
	    // Fill the map
	    for (int i=0; i<1000; ++i) {
		map.put (String.valueOf (i), new Integer (i));
	    } 
	    
	    File file = File.createTempFile("lrumap", "fortest");
	    
	    // Do a serialize / deserialize loop, til memory breaks
	    try {
		for (int l=0; l<100; ++l) {
		    {
			FileOutputStream fileStream = new FileOutputStream(file);
			ObjectOutputStream objectStream =
			    new ObjectOutputStream(fileStream);
			objectStream.writeObject(map);
			fileStream.close();
		    }
		    {
			FileInputStream fileStream = new FileInputStream(file);
			ObjectInputStream objectStream = new ObjectInputStream(fileStream);
			map = (HashMap) objectStream.readObject();
			fileStream.close();
		    }
		    
		} 
		
	    } catch (OutOfMemoryError oome) {
		fail (oome.getClass ().getName ());
	    } 
	}
	


	{
	    // Then use apache LRUMap (same behavior with Linked map, I did not
test the others)
	    LRUMap map = new LRUMap (1000);
	    // Fill the map
	    for (int i=0; i<1000; ++i) {
		map.put (String.valueOf (i), new Integer (i));
	    } 
	    
	    File file = File.createTempFile("lrumap", "fortest");
	    
	    // Do a serialize / deserialize loop, til memory breaks
	    try {
		for (int l=0; l<100; ++l) {
		    {
			FileOutputStream fileStream = new FileOutputStream(file);
			ObjectOutputStream objectStream =
			    new ObjectOutputStream(fileStream);
			objectStream.writeObject(map);
			fileStream.close();
		    }
		    {
			FileInputStream fileStream = new FileInputStream(file);
			ObjectInputStream objectStream = new ObjectInputStream(fileStream);
			map = (LRUMap) objectStream.readObject();
			fileStream.close();
		    }
		    
		} 
		
	    } catch (OutOfMemoryError oome) {
		fail (oome.getClass ().getName ());
	    } 
	}

    }

-- 
o----------------------------------o
|           Marc Jambert           |
| marc.jambert@vegatechnologies.fr |
|                                  |
|       (tel) 05-67-77-19-72       |
|       (fax) 05-67-77-19-98       |
o----------------------------------o
|        Vega Technologies         |
o----------------------------------o


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org