Garbage Collector Question

Discussion in 'Bukkit Help' started by ResultStatic, Apr 4, 2015.

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

    ResultStatic

    This is more of java question but for some reason when i call Runtime.getRuntime().gc(); it frees up so much more ram than the regular garbage collector cycle does. like for instance after 6 hours of runtime the server will be at around 1-3gb of free ram in its garbage collection cycle. then instantly when i run a command that calls Runtime.getRuntime().gc() the server freezes for 1 second then its back up to 4-6 gb of free ram. I'm about to make a runnable that calls Runtime.getRuntime().gc() every hour. Why is it doing this, is the garbage collector broken and Java seriously needs a delete <object> mechanic like in c++ and c#


    if you dont believe me here is a screenshot. one garbage collection cycle. http://gyazo.com/859df3b8dc91719bd50d8131bb0c43d2

    then i run the command that calls Runtime.getRuntime().gc(); then boom instantly 5gb more free ram in each cycle.

    http://gyazo.com/f41aeecf3b2e048503e3dafaca9b775d
     
    Last edited: Apr 4, 2015
  2. Offline

    teej107

    @ResultStatic It's because you shouldn't need to call the GC.
     
  3. Offline

    ResultStatic

    @teej107 look at my edit

    barely scrapping by with 350 mb of ram in the first cycle, sometimes it even runs out of ram and freezes the server. then i run the command and instantly it frees up 5gb of ram
     
  4. Offline

    teej107

    @ResultStatic You should leave the GC alone and let Java handle it. Resources will be freed when necessary.
     
  5. Offline

    ResultStatic

    ok why was my thread moved to bukkit help this is a plugin development question. ugh i swear these forums are ruined. This is a question involving code run inside my plugin, i dont see why it cant be included in the plugin development section
     
  6. Offline

    teej107

    It doesn't have much to do with Bukkit at all in fact. I would've put in Offtopic TBH.

    Yes I did read your post. Why are you even trying to use the GC?
     
    nverdier likes this.
  7. Offline

    ResultStatic

    @teej107 look at the screenshots, the normal gc cycle is not freeing up memory. When i dont call the manual gc command it runs out of memory, but when i do it frees up 5gb of free ram
     
  8. Offline

    teej107

    @ResultStatic
    if the resources can be freed.
     
  9. Offline

    ResultStatic

    @teej107 well if they cant be freed then why is manual garbage collection freeing them when the automatic gc isnt?
     
  10. Offline

    teej107

    The automatic GC decides the best time to free resources. In short: You shouldn't be needing to use gc() method.
     
  11. Offline

    ResultStatic

    @teej107 Are you even reading what i'm saying. the automatic isnt freeing up memory as well as the manual one does. the server runs out of memory with the automatic gc over a long period of time, but once i call the manual gc it frees up tons of memory that the automatic gc wasnt finding.
     
  12. Offline

    teej107

    @ResultStatic So the problem is that the server is running out of memory? An error will occur when the server truly runs out of memory.
     
  13. Offline

    ResultStatic

    @teej107 well its not oom but it gets so close the server starts freezing and lagging. sometimes it gets as low as 50mb of free memory and in that screenshot above it was at 350mb of free memory, then i call the manual gc and it goes to 5-7gb of free ram each cycle.
     
  14. Offline

    teej107

    @ResultStatic Are you sure the problem isn't because of poorly coded plugins?
    Objects can't be freed when there is a strong reference to them like keeping Players in Collections/Fields.
     
    nverdier likes this.
  15. Offline

    ResultStatic

    @teej107 all of our plugins are custom coded and i have checked every player reference in jprofiler and no player references are found excepting the references in Bukkit. And if it was memory leaks why is a manual gc freeing all of them?
     
  16. Offline

    teej107

    @ResultStatic Player is just an example as it is the most common mistake that people make. It could be other things as well.
     
  17. Offline

    ResultStatic

    @teej107 yes but that still doesnt change the fact that manual gc is freeing all of that memory... if they had references then a manual gc wouldnt free it, no?
     
  18. Offline

    teej107

  19. Offline

    ResultStatic

    @teej107 well im going to have to tune the garbage collector and manual gc every hour
     
  20. Offline

    nverdier

  21. Offline

    teej107

    Did you? Tuning was a suggestion made in the link.
     
  22. Offline

    nverdier

    @teej107
     
  23. Offline

    teej107

    @nverdier What I was saying basically. But read the second answer.
     
    nverdier likes this.
  24. Offline

    nverdier

    Meh. :p
     
    teej107 likes this.
Thread Status:
Not open for further replies.

Share This Page