Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak in Function #2337

Closed
Wealthyturtle opened this issue Aug 5, 2019 · 10 comments
Closed

Memory Leak in Function #2337

Wealthyturtle opened this issue Aug 5, 2019 · 10 comments
Assignees
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. completed The issue has been fully resolved and the change will be in the next Skript update. priority: high Issues with potentially high impact that could be harmful to users.

Comments

@Wealthyturtle
Copy link
Member

Wealthyturtle commented Aug 5, 2019

Description

When a function returns a variable, and the function is called but does not actually get stored in a variable (local or global), it causes a leak

Steps to Reproduce

function lore_add(i: item, s: string) :: item:
    set line (size of {_i}'s lore)+1 of {_i}'s lore to {_s}
    print_lore({_i})
    return {_i}

function print_lore(i: item):
    set {_lore::*} to {_i}'s lore
    set {_c} to 1
    loop {_lore::*}:
        broadcast "L%{_c}%: %loop-value%"
        increase {_c} by 1

command /test:
    trigger:
        lore_add(dirt, "This should only appear once")

If you run the /test command multiple times, this occurs:
image
As you can see, at the first call of /test there's only 1 line of lore, but then the next call of /test has 2, followed by 3, ...

Expected Behavior

Prior lore should not be stored, since it's technically local

Errors / Screenshots

Server Information

  • Server version/platform: Spigot 1.14.4
  • Skript version: Skript 2.4-beta5

Additional Context

Should probably test other vectors other than lore, to confirm if it's limited to lore or all expressions

Also, @bensku

@TheBentoBox TheBentoBox added bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. priority: high Issues with potentially high impact that could be harmful to users. labels Aug 5, 2019
@bensku
Copy link
Member

bensku commented Aug 5, 2019

Since when does this occur?

@Wealthyturtle
Copy link
Member Author

Can test other versions of Skript, give me a moment

@Wealthyturtle
Copy link
Member Author

Wealthyturtle commented Aug 5, 2019

Skript 2.4-alpha1 (Spigot 1.14.4): Exists
Skript 2.3.7 (Spigot 1.13.2): Exists
Skript 2.3.1 (Spigot 1.13.2): Exists
Skript 2.2-dev37c (Spigot 1.12.2): Exists

From here on out, running modified Skript (bug exists on Skript 2.4-beta5)

function lore_add(i: item, s: string) :: item:
    set {_lore::*} to {_i}'s lore
    set line (size of {_lore::*})+1 of {_i}'s lore to {_s}
    broadcast "%size of {_lore::*}%"
    return {_i}

command /test:
    trigger:
        lore_add(dirt, "This should only appear once")

Skript 2.2-dev36 (Spigot 1.11.2) Exists
Skript 2.2-dev34 (Spigot 1.11.2) Exists
Skript 2.2-dev33 (Spigot 1.11.2) Does not exist
Skript 2.2-dev32c (Spigot 1.11.2) Does not exist
Skript 2.2-dev31c (Spigot 1.11.2): Does not exist
Skript 2.2-dev29 (Spigot 1.11.2): Does not exist
Skript 2.2-dev13 (Spigot 1.9): Does not exist
Skript 2.1.2 (CraftBukkit 1.7.2): Functions no longer supported
Still testing other Skript versions (will update this message as I go on)

@Wealthyturtle
Copy link
Member Author

@bensku Seems like Skript 2.2-dev34 broke it, try starting from there?

@bensku
Copy link
Member

bensku commented Aug 5, 2019

Thanks for investigating it! dev34 is so old that I'm probably not going to investigate there. Rewriting messy parts of the function system is likely faster, and produces other benefits (readable code) too.

Unfortunately this means that the fix will take a while.

@bensku bensku self-assigned this Aug 5, 2019
@TheLimeGlass
Copy link
Collaborator

Potentially related #2279

@bensku bensku added the completed The issue has been fully resolved and the change will be in the next Skript update. label Aug 31, 2019
@bensku
Copy link
Member

bensku commented Aug 31, 2019

Likely fixed in #2383. In the end, this was not terribly hard to fix.

@bensku bensku added completed The issue has been fully resolved and the change will be in the next Skript update. and removed completed The issue has been fully resolved and the change will be in the next Skript update. labels Aug 31, 2019
@bensku bensku closed this as completed Sep 3, 2019
@Wealthyturtle
Copy link
Member Author

I just found out that this issue has been reintroduced in some recent Skript update, as this memory leak still occurs in Skript 2.5-alpha3.

@Wealthyturtle Wealthyturtle reopened this Jun 18, 2020
@Wealthyturtle Wealthyturtle removed the completed The issue has been fully resolved and the change will be in the next Skript update. label Jul 10, 2020
@Wealthyturtle
Copy link
Member Author

Just to note, it seems like the memory leak was never resolved by the function overhaul. See #2877 for some memory profiles taken that show the leak.

@TPGamesNL
Copy link
Member

TPGamesNL commented Mar 28, 2021

The lore part of this issue is caused by #3779 (see the comment for example with items)
The loop memory leak (#2877) is caused by Loop#current not being removed from:
image
(it might also be Loop#currentIter, but that field at least has remove called somewhere, so it's more likely to be Loop#current)

So this doesn't just affect functions

@TPGamesNL TPGamesNL added the PR available Issues which have a yet-to-be merged PR resolving it label Mar 28, 2021
@TPGamesNL TPGamesNL added completed The issue has been fully resolved and the change will be in the next Skript update. and removed PR available Issues which have a yet-to-be merged PR resolving it labels May 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. completed The issue has been fully resolved and the change will be in the next Skript update. priority: high Issues with potentially high impact that could be harmful to users.
Projects
None yet
Development

No branches or pull requests

6 participants