kikito / middleclass

Object-orientation for Lua
https://github.com/kikito/middleclass
MIT License
1.77k stars 190 forks source link

Memory Leak in middleclass.lua #3

Closed kikito closed 13 years ago

kikito commented 13 years ago

Reference: http://love2d.org/forums/viewtopic.php?f=4&t=2278

Hi

Newbie here, I have been experimenting a bit with Lua and the Middleclass library, an apparent memory leak with Middleclass has got me totally stumped. Is this really a leak or am I misunderstanding something.

I cut my code down to just the following lines

Code: Select all require "middleclass"

local oPlayer = class("A Player")      -- This single line is enough to show a leak

collectgarbage("collect")
local endMem = string.format("\nMemory used after Garbage Collect = %.1f kbytes", collectgarbage("count"))
print (endMem)

If I run this code repeatedly from a Lua console with dofile("myTest.lua") I get the following increasing memory usage. Memory used after Garbage Collect = 43.8 kbytes Memory used after Garbage Collect = 46.0 kbytes Memory used after Garbage Collect = 48.2 kbytes Memory used after Garbage Collect = 50.6 kbytes

If I add the line oPlayer = nil, that makes no difference either.

kikito commented 13 years ago

It is, indeed, a memory leak. Working on fixing it right now.

kikito commented 13 years ago

made the _classes table properly weak. This closed by 5c361fe2df9336a78ddb157b2bab7860eea4e3f5