This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
H4X0RZ's profile picture

Memory problems when using OO?

Started by H4X0RZ, 22 August 2015 - 12:12 PM
H4X0RZ #1
Posted 22 August 2015 - 02:12 PM
I'm feeling kinda stupid right now. I were working on a simple game to test my OO utility. Now it actually works, but when I run the program multiple times, it will crash with a "too long without yielding" in my type overwrite at line 19. Also it will become slower every time I ran the script.

At first I thought it's because _G is filled with stuff, so I added code to delete every class at the beginning of the script (the end of the utility) and it actually helped, but didn't fix the problem.

Does anyone have any idea what I did wrong?

Greetings,
H4X0RZ
InDieTasten #2
Posted 22 August 2015 - 02:16 PM
without looking into your code I would highly assume it doesn't have to do with memory allocation. good luck nevertheless
Anavrins #3
Posted 22 August 2015 - 04:25 PM
In your GitHub repository, I can't seem to find your "Class" file, which is where the problem probably is.
H4X0RZ #4
Posted 22 August 2015 - 04:32 PM
In your GitHub repository, I can't seem to find your "Class" file, which is where the problem probably is.

You mean this? http://pastebin.com/zDf5pMsK
Exerro #5
Posted 22 August 2015 - 07:27 PM
I think your type() function might have something to do with it. Every time you run the OO utility, it seems the type function is overridden in a way that calls the old type function, so you'd get your overridden one essentially calling itself 5 times if you ran the utility 6 times.
MKlegoman357 #6
Posted 22 August 2015 - 08:58 PM
I think your type() function might have something to do with it. Every time you run the OO utility, it seems the type function is overridden in a way that calls the old type function, so you'd get your overridden one essentially calling itself 5 times if you ran the utility 6 times.

Or rather 63 times, to be more precise. That's because you call it two times inside your overriden function. Try something like this, and report the result:


_G["type"] = function(obj)
  local typ = _type(obj)
  if(typ == "table") then
    if(obj._CLASS_NAME_) then
      return obj._CLASS_NAME_,true
    end
  end
  return typ
end
Edited on 22 August 2015 - 06:59 PM
H4X0RZ #7
Posted 23 August 2015 - 12:01 AM
I think your type() function might have something to do with it. Every time you run the OO utility, it seems the type function is overridden in a way that calls the old type function, so you'd get your overridden one essentially calling itself 5 times if you ran the utility 6 times.

Or rather 63 times, to be more precise. That's because you call it two times inside your overriden function. Try something like this, and report the result:


_G["type"] = function(obj)
  local typ = _type(obj)
  if(typ == "table") then
	if(obj._CLASS_NAME_) then
	  return obj._CLASS_NAME_,true
	end
  end
  return typ
end

Thanks! (to everyone who posted here.)

The problem indeed was the type function. But it wasn't fixed after using what MKlegoman told me (even though it is better performance-wise). I fixed it by changing
local _type =type
to
local _type = _G.rawtype or type