java.lang.OutOfMemoryError: PermGen space

Discussion in 'Plugin Development' started by Techy4198, Jul 12, 2013.

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

    Techy4198

    ok i get this error a lot on my server after a /reload, but it only occurs when using my plugin. any info about what could be causing this? also another question, will the onDisable() and onEnable() methods run when the server is reloaded?
     
  2. Offline

    MarianDCrafter

    Yes, onEnable() and onDisable() run when the server reloads.
     
  3. Offline

    Webster56

    Tell us where this happens in the code of your plugin ;)
     
  4. Offline

    Chinwe

    Does this happen the first time you reload and enable your plugin, or after many reloads?
    Reloads can cause memory leaks, so after many it can cause your server to crash with this error: try restarting the server ;)
     
  5. Offline

    ZeusAllMighty11

    You probably have memory leaks.


    Or your server has very little ram, not enough needed
     
  6. Offline

    Techy4198

    Webster56 it seemed to start happening after i implemented water pistols, which make heavy use of metadata. metadata is probably the problem.
    Chinwe only after several reloads.
    TheGreenGamerHD i don't know much about memory leaks but i assume it is something about not properly discarding variables and just leaving them in memory to cause problems. and i have plenty of ram in my pc, 6GB (quite good for a laptop) so can you tell me, how do i specify how much memory is allocated to the server? is it the -Xmx####M line in the .bat that starts it?

    actually i have this line in my .bat:
    java -Xms1024M -Xmx2048M -jar "%~dp0craftbukkit.jar"
    what part must i change? the -Xms part or the -Xmx part? also can you tell me what each one does?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  7. Offline

    ZeusAllMighty11

    I run my server with 1/2gb of ram, works just fine for dev purposes.


    You need to upload your code to github or pastebin and we can help look it over.
     
  8. Offline

    Chinwe

    Techy4198
    Is this the water pistol plugin that loops through all players every tick and sprays item drops if they're sneaking? It's quite intensive :oops:
     
  9. do you have other plugins that your own plugins installed? try removing them and see if it happens again

    EDIT: you can analyze a memory dump of your server to see if its caused by your plugin
     
  10. Offline

    Webster56

    Ain't there something that tells you which line in your plugin the Error happens ?
     
  11. a out of memory error is like a stolen car, you know it has happened, but you don't know who did it.
     
    hawkfalcon, Seadragon91 and dillyg10 like this.
  12. Offline

    Techy4198

    Chinwe yes thats the one, but like i said, it's not intensive at all. if it is a water pistol jet entity, it doesnt hang around for long. if it isn't, it runs none of the check code after that.
     
  13. Offline

    blablubbabc

    I think to remember, that "PermGen" space is something else than "heap space". So it's not a problem with how many ram you have allocated to java heap space via xms / xmx, but with your jvm's internal space where it saves the class files etc. (I think) So it's more likly an issue with loading/unloading of plugins and especially their class files by the plugin class loader -thing. Something like that. Here is an article I found about what it is: http://plumbr.eu/blog/what-is-a-permgen-leak

    However, if you wish to higher the perm gen space, you can use this argument: -XX:MaxPermSize=128M
     
  14. Offline

    Techy4198

    blablubbabc i found something important on that page:
    which reminded me, even though that is about threads, and i do not create any threads, i do not terminate my scheduled sync repeating tasks in the onDisable() method. how do i do so?
     
  15. Techy4198 This should do the trick. getServer().getScheduler().cancelTasks(plugin);
     
  16. Offline

    Techy4198

    would it be a bad idea to impement server-wide task cancelling for all plugins?
    Code:
            for(Plugin pluginToCancel : Bukkit.getPluginManager().getPlugins())
            getServer().getScheduler().cancelTasks(pluginToCancel);
     
  17. Offline

    blablubbabc

    Yes it would
     
  18. Offline

    Techy4198

    more info? i do not really see the problem
     
  19. Offline

    blablubbabc

    You will very likly cancle an important task of other plugins. These plugins should cancle their tasks by their own if necesarry, because they know best when and how to cancle them.
     
  20. Offline

    Techy4198

    no i mean when the server is reloaded or shut down, when all the plugins are unloaded anyway
     
  21. Offline

    ZeusAllMighty11

    Terrible idea.

    The issue is most likely your own plugin, you need to optimize it.
     
  22. Offline

    Techy4198

    how would i go about optimizing a plugin with so many features lol. and what do you mean by optimize? make the code more efficient? in what way?
     
Thread Status:
Not open for further replies.

Share This Page