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

bug(memory): gm <-> lua memory leak #16

Open
xiaoxiao921 opened this issue Aug 27, 2024 · 2 comments
Open

bug(memory): gm <-> lua memory leak #16

xiaoxiao921 opened this issue Aug 27, 2024 · 2 comments

Comments

@xiaoxiao921
Copy link
Member

Klehrik says:
It seems that iterating through large (perhaps all but it's more noticeable with more elements) gamemaker arrays often (like every frame) causes a gradual memory leak(?)

Example (in __input_system_tick):

-- This causes memory usage to increase unbounded
local class_item = gm.variable_global_get("class_item")
for _, i in ipairs(class_item) do
    -- empty
    -- nothing else has to be done, just iterating causes this
end

Just open task manager and watch RoRR memory usage for a few minutes
I tried with a newly created array containing 200 0s as well and the same thing happens


Related code: https://github.com/return-of-modding/ReturnOfModding/blob/5a15338e95b4bb6a1b075fea9276d3056948a6d3/src/rorr/gm/pin_map.hpp

@xiaoxiao921 xiaoxiao921 changed the title bug(memory): gm <-> memory leak bug(memory): gm <-> lua memory leak Aug 27, 2024
@Klehrik
Copy link

Klehrik commented Aug 27, 2024

I think the problem might just be with using ipairs to iterate over it

-- This seems to be fine
local class_item = gm.variable_global_get("class_item")
local size = gm.array_length(class_item)
for i = 0, size - 1 do
    gm.array_get(class_item, i)
end

@Klehrik
Copy link

Klehrik commented Aug 28, 2024

Additionally, accessing arrays with lua syntax instead of gm.array_get also causes gradual memory usage

-- This causes increasing memory usage
local class_item = gm.variable_global_get("class_item")
local size = gm.array_length(class_item)
for i = 0, size - 1 do
    local item = class_item[i]
end


-- This is fine
local class_item = gm.variable_global_get("class_item")
local size = gm.array_length(class_item)
for i = 0, size - 1 do
    local item = gm.array_get(class_item, i)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants