[MC-3256] Memory leak when starting large TNT chain reactions Created: 17/Nov/12 Updated: 13/Apr/16 Resolved: 24/Jul/14 |
|
| Status: | Resolved |
| Project: | Minecraft: Java Edition |
| Component/s: | None |
| Affects Version/s: | Minecraft 1.4.4, Minecraft 1.4.7, Minecraft 1.5, Minecraft 1.6.4, Minecraft 1.7.2, Minecraft 1.7.5 |
| Fix Version/s: | Minecraft 1.7.10 |
| Type: | Bug | ||
| Reporter: | Nico Bergemann | Assignee: | Unassigned |
| Resolution: | Fixed | Votes: | 2 |
| Labels: | explosion, leak, memory, tnt | ||
| Environment: |
Windows 7 x64, Java 1.7.0_09-b05 |
||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Confirmation Status: | Unconfirmed | ||||||||
| Description |
|
This bug has been in Minecraft for a good while. When starting a chain reaction with several hundreds of TNT blocks involved, the game will start to allocate massive amounts of memory until the virtual machine heap space (-Xmx) is fully exhausted, with the well-known "Out of memory" screen as a result. Steps to reproduce: create a superflat world, preset "2;128x46", ignite any TNT block, wait a few seconds. This is caused by the dynamic object pooling for vector and bounding box objects combined with very expensive explosion damage/propulsion calculations. Each explosion potentially requires some thousand vectors and a few hundred bounding boxes, whose instances are all stored in a pool for the duration of the current tick. The solution is pretty simple: set a per-tick limit for the object pool list. If a certain limit is passed (I'd recommend 10-20k), return any additional objects always newly constructed so they can be garbage-collected once they're no longer being used. This also allows the use of fixed-size arrays, which could be a little faster than lists. The attachments below contain some example code that allows me to perform explosions like on a TNT superflat world as above with just 4 GB RAM without any known side effects. (of course, the enormous amount of entities and TNT block meshes will also produce out of memory errors at some point, but much later than in vanilla) This obviously won't fix the FPS performance issues during mass explosions, but at least you'll be able to see the result after some time without having 32+ GB RAM. |
| Comments |
| Comment by Cooper Stinson [ 13/Apr/16 ] |
|
i was using a ipod mod and i used the app explosion and i did explosion power:2000 and my game lagged like freak heck and i tryed loading another world and it crashed with the error: out of ram. |
| Comment by Nico Bergemann [ 24/Jul/14 ] |
|
I've repeated the test with 14w30b and it looks like it won't run out of memory anymore. I think it has been fixed in 1.7.10 already, since there's no object pool for vectors anymore, which essentially fixes this issue. |
| Comment by Deleted account [ 25/May/14 ] |
|
Is this still a concern in the current Minecraft version 14w21b / Launcher version 1.4.4 or later? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases. |
| Comment by tuki [ 19/Mar/14 ] |
|
still happens. i tried it with tnt minecarts (more than about 20) and it lags a bit then crashes |
| Comment by Nico Bergemann [ 01/Dec/13 ] |
|
Yes, it's still happening, although the game now shuts down the internal server properly instead of crashing altogether. |
| Comment by F. Carl Feiler [ 26/Sep/13 ] |
|
Crash report from Launcher 1.2.5, Minecraft version 1.6.4. Created superflat world with 64 layers of TNT, ignited with a redstone torch. A few seconds later, "Out of Memory" dialog window, "Minecraft could not continue, as it has run out of memory." |
| Comment by F. Carl Feiler [ 26/Sep/13 ] |
|
I saw this problem in 1.6.4, although I haven't exactly duplicated the If you haven't gotten 50 more useful replies by the time you read this, let HTH, On Wed, Sep 25, 2013 at 10:42 PM, [Mod] CubeTheThird (JIRA) < |
| Comment by Klocko [ 25/Apr/13 ] |
|
There's a way to remove all of the Primed TNT Entities so you can de-activate the TNT and go back into your world safely, if you have got MCEdit! 1. Open your world in MCEdit |
| Comment by Nico Bergemann [ 16/Mar/13 ] |
|
Yes, it is still present in 1.5. I updated the version tags. |
| Comment by Nico Bergemann [ 17/Nov/12 ] |
|
Added MCP-style code example for fixed object pooling |