Impensus Posted June 1, 2020 Share Posted June 1, 2020 Hi guys, I recently made a big expansion to a script of mine. I went from the classes Farming, Banking & Teleports to a script that contains about 13 classes total. The reason I mention this, is that since then my script eats about 500mb RAM (fair bit more than it did originally) and is sometimes unresponsive/takes a while to stop. I've noticed this behaviour even when the script is looping in the "Farming" methods, despite this behaviour not existing before the additional classes were added. No changes have been made to the original classes so I am unsure why they now are a lot slower. I'm wondering if you guys have any generic tips/anecdotal advice on problems you have encountered causing similar behaviour. Thanks!! Quote Link to comment Share on other sites More sharing options...
Ace99 Posted June 1, 2020 Share Posted June 1, 2020 My best go-to's are to comment everything new and then uncomment it piece by piece so you know what works well, and then just log everything and track the log to see what is being logged during a period of lag/freezing. You could be calling something an unreal amount of times and not know it, creating an object over and over, not caching info efficiently, or not creating optimal methods/loops in general. Do you have multiple threads running, external API calls, web interfacing? Address things like that. Quote Link to comment Share on other sites More sharing options...
Nbacon Posted June 1, 2020 Share Posted June 1, 2020 I agree with Ace. This sounds like your tring to use something that is null fixing this will help the memory issue. Fixes? Try/catch around the loop this is a bandaid for gun shot or null check everthing this is just a pain in the ass but saved me many heart aches . Follow questions to get a better answer. Can you stop the script after sometime or do you have to force kill it if this does happen? Do can you see the log? Is it only in one section of the script or you can't tell. Quote Link to comment Share on other sites More sharing options...
Impensus Posted June 2, 2020 Author Share Posted June 2, 2020 On 6/1/2020 at 9:59 PM, Nbacon said: I agree with Ace. This sounds like your tring to use something that is null fixing this will help the memory issue. Fixes? Try/catch around the loop this is a bandaid for gun shot or null check everthing this is just a pain in the ass but saved me many heart aches . Follow questions to get a better answer. Can you stop the script after sometime or do you have to force kill it if this does happen? Do can you see the log? Is it only in one section of the script or you can't tell. 1. Sometimes if I wait the script stops. Other times I have to force kill it. I’m guessing that after I’ve ran and stopped it too many times the client eventually becomes unresponsive and needs to be killed. 2. I can see the logs, there are no visible NPEs 3. It’s likely that it is one or more sections of the script. However I don’t think it’s code that is currently running (if that’s possible) as like I mentioned in the body the code in this loop worked fine before I added new classes. I’m guessing some errors occur during class/variable instantiation that cause these errors but don’t give visible NPEs etc. Quote Link to comment Share on other sites More sharing options...
Nbacon Posted June 3, 2020 Share Posted June 3, 2020 Sorry I can't help you more. Its most likly something supper small. 17 hours ago, Impensus said: I’m guessing that after I’ve ran and stopped it too many times the client eventually becomes unresponsive and needs to be killed. Sounds like a mermory leak or a threading problem. If a memory leak limit recursion and making new objects. If a threading problem try this. (I like ExecutorSevices to kill all threads.) Quote private ExecutorService executor = Executors.newFixedThreadPool(5);//mine is 5 because i have 4 threads private Runnable runnable; runnable = () -> { if (isStoped()) { executor.shutdownNow(); executorSend = null; } try { //1 time thread task but works like a loop executor.submit(runnable); } catch (Exception e) { log(e) executor.submit(runnable); } }; 17 hours ago, Impensus said: I can see the logs, there are no visible NPEs That sucks. 17 hours ago, Impensus said: It’s likely that it is one or more sections of the script. However I don’t think it’s code that is currently running (if that’s possible) as like I mentioned in the body the code in this loop worked fine before I added new classes. Maybe take out features add them back 1 at a time till you find the problem? Quote Link to comment Share on other sites More sharing options...