WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   My favourite addon leaks memory (https://www.wowinterface.com/forums/showthread.php?t=57263)

SDPhantom 07-08-19 06:01 PM

Quote:

Originally Posted by DashingSplash (Post 332812)
I got a bit intrigued by the table wipe discussion since I used it for my first AddOn that I made (or rather an early version of my first AddOn). Since I had trouble with the tables keeping their old values when the UPDATE_BINDINGS event was triggered I had to wipe the tables as shown below.

Lua Code:
  1. local table_1 = {t = {}, st = {}, ct = {}, at = {}} --Filled after dashingUpdate has executed
  2. local table_2 = {t2 = {}, st2 = {}, ct2 = {}, at2 = {}} --Filled after dashingUpdate has executed
  3.  
  4. local function dashingUpdate(self, event, ...)
  5.     for _, tableWipe in pairs(table_1) do
  6.         wipe(tableWipe)
  7.     end
  8.    
  9.     for _, tableWipe in pairs(table_2) do
  10.         wipe(tableWipe)
  11.     end
  12. end

Would this actually be an OK way to do it, or would I get problems if the addon had been updating a lot more?

Depends on what the rest of your code looks like. If you're already running the same loops later in the code when you write to the tables, do it there.

doofus 07-09-19 02:06 AM

Quote:

Originally Posted by Ketho (Post 332810)
This is why you should post your code in the first place

Nah, my code is many thousands of lines, I would not even know where to start looking, let alone which sections to upload for public scrutiny.

The "error" was not obvious, you'd have to sit in range and in front of the dummy and in combat for a LONG time to start noticing a subtle screen jerkiness at first, gradually getting worse. And every time you made a change to the code, you'd need to start all over again (due to the /reload).

To trace it I added a short exit in various places (10 places), controlled by a runtime flag, which I could set using slash commands without reloading the addon. I let it run until I noticed the screen jerkiness (made coffee, boiled the kettle, cut the grass etc) and once the jerkiness was unmistakable then I started modifying this flag to cause a short circuit exit and eventually I hit the point where the jerkiness disappeared or re-appeared, and that was around the CreateFrame. That's how I got the culprit.

doofus 07-09-19 02:15 AM

Quote:

Originally Posted by Kanegasi (Post 332781)
I don't understand this part. What do you mean "tables inside tables"? Is wipe not letting you clean that table which happens to be in a table or do you have nested tables inside the table you're trying to clean? As for the fail part, are you getting errors? What happened when you used wipe?

I initially used wipe() as per suggestions, thinking it would eliminate a memory leak and was monitoring performance by hovering the mouse over the ? (wow menu). I realised that if I had a table inside a table then wipe() would not help and memory appeared to be steadily increasing like it did before. If I was using just a single dimensional table then wipe() appeared to stop the memory leak.

Soon after that I discovered I could force GC by calling garbagecollect() so did not delve further into wipe().

Then I discovered that my issue was around CreateFrame() because I was not deleting the previous frames, and read that you cannot anyway, but you must reuse them.

Resike 07-09-19 03:09 AM

Quote:

Originally Posted by doofus (Post 332822)
I initially used wipe() as per suggestions, thinking it would eliminate a memory leak and was monitoring performance by hovering the mouse over the ? (wow menu). I realised that if I had a table inside a table then wipe() would not help and memory appeared to be steadily increasing like it did before. If I was using just a single dimensional table then wipe() appeared to stop the memory leak.

Soon after that I discovered I could force GC by calling garbagecollect() so did not delve further into wipe().

Then I discovered that my issue was around CreateFrame() because I was not deleting the previous frames, and read that you cannot anyway, but you must reuse them.

You know that there are ppl here that might be able to see errors a lot faster without even logging into the game due they have more experience with the API and Lua in general right? For example there are some APIs that leak memory even when used correctly.

Seerah 07-09-19 06:07 PM

Yeah, there are certain places we look first. ;)


All times are GMT -6. The time now is 05:08 AM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI