Jump to content

Memory leak


Recommended Posts

Posted

There's a memory leak in this script, but can't find it. 

    boolean isSplashing;
    long magicxp;

    private Predicate<NPC> suitableNPC = n ->
            getMap().canReach(n) &&
                    n.getHealthPercent() > 0 &&
                    n.hasAction("Attack") &&
                    !n.isUnderAttack() &&
                    getMap().realDistance(n) < 15;

    

public int onLoop() throws InterruptedException {
        isSplashing = true;
        magicxp = getSkills().getExperience(Skill.MAGIC);
        sleep(random(3600,4800));
        if (magicxp == getSkills().getExperience(Skill.MAGIC)) {
            isSplashing = false;
        }
        if (!myPlayer().isUnderAttack() || !isSplashing) {
            if (getInventory().contains("Air rune") && getInventory().contains("Mind rune") && getInventory().contains("Fire rune")) {
                java.util.List<NPC> npcs = getNpcs().getAll().stream().filter(suitableNPC).collect(Collectors.toList());
                if (!npcs.isEmpty()) {
                    npcs.sort(Comparator.<NPC>comparingInt(a -> getMap().realDistance(a)).thenComparingInt(b -> getMap().realDistance(b)));
                    if (npcs.get(0).interact("Attack")) {
                        sleep(random(3000));
                    }
                }
                sleep(random(3000,4000));
            } else {
                stop();
            }
        }
        return random(300,400);
    }

Threw some stuff around to see if something changed. In like 4-5 hours the memory usage went from 600MB to 1.2GB.

Posted
1 minute ago, The Undefeated said:

What is complex in your eyes?

nothing really just dont think you need a list for 1 target

 private Predicate<NPC> suitableNPC = n ->
            getMap().canReach(n) &&
                    n.getHealthPercent() > 0 &&
                    n.hasAction("Attack") &&
                    !n.isUnderAttack() &&
                    getMap().realDistance(n) < 15;
 java.util.List<NPC> npcs = getNpcs().getAll().stream().filter(suitableNPC).collect(Collectors.toList());
                if (!npcs.isEmpty()) {
                    npcs.sort(Comparator.<NPC>comparingInt(a -> getMap().realDistance(a)).thenComparingInt(b -> getMap().realDistance(b)));

 

Posted (edited)
4 minutes ago, raijin said:

nothing really just dont think you need a list for 1 target


 private Predicate<NPC> suitableNPC = n ->
            getMap().canReach(n) &&
                    n.getHealthPercent() > 0 &&
                    n.hasAction("Attack") &&
                    !n.isUnderAttack() &&
                    getMap().realDistance(n) < 15;

 java.util.List<NPC> npcs = getNpcs().getAll().stream().filter(suitableNPC).collect(Collectors.toList());
                if (!npcs.isEmpty()) {
                    npcs.sort(Comparator.<NPC>comparingInt(a -> getMap().realDistance(a)).thenComparingInt(b -> getMap().realDistance(b)));

 

Oh yeah, copied it from Macro killer, just because I was that lazy. But still doesn't fix the memory leak..

 

Edited by The Undefeated

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...