Thread Tools Display Modes
07-08-19, 06:01 PM   #21
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by DashingSplash View Post
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.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
07-09-19, 02:06 AM   #22
doofus
A Chromatic Dragonspawn
Join Date: Feb 2018
Posts: 158
Originally Posted by Ketho View Post
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.
  Reply With Quote
07-09-19, 02:15 AM   #23
doofus
A Chromatic Dragonspawn
Join Date: Feb 2018
Posts: 158
Originally Posted by Kanegasi View Post
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.
  Reply With Quote
07-09-19, 03:09 AM   #24
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by doofus View Post
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.
  Reply With Quote
07-09-19, 06:07 PM   #25
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Yeah, there are certain places we look first.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » My favourite addon leaks memory

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off