Blocks hog up memory?

Discussion in 'Plugin Development' started by asdaarg, Apr 9, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    asdaarg

    Code:
    for(World W:S.getWorlds()){
    	AWorld w=getWorld(W);
    	for(Chunk c:W.getLoadedChunks()){
    		for(int x=0;x<16;x++)
     			for(int y=0;y<128;y++)
     				for(int z=0;z<16;z++)
    					//p+=c.getBlock(x, y, z).getTypeId();
    					p+=W.getBlockTypeIdAt(c.getX()<<4|x, y, c.getZ()<<4|z);//this one doesn't hog up memory
    	}
    }
     System.out.print(p);
    
    Uncommenting the first p+= line and commenting the second, causes memory usage to go from 299M to 1.1G and stays there. It seems that the Blocks gotten with getBlock doesn't get removed from memory.
     
  2. Offline

    Argomirr

    Block data is cached for performance when you make a getBlock() call, which can eat up a lot of memory if you do stuff like scanning an area for blocks. You should use World.getBlockIdAt(x, y, z) with this kind of thing.
     
  3. Offline

    asdaarg

    That's all fine except when you want to set the block id or look at other properties of the blocks. If its really a cache, then way too many blocks are being cached IMHO.
     
  4. Offline

    Argomirr

    I agree, it can be difficult at times. Having a way to disable caching temporarily would be useful...
     
Thread Status:
Not open for further replies.

Share This Page