Memory Leak ?
Hi all,
I was doing a simple LDB to hide the class order bar for not be shown under docking station. But I miss something to show a panel so I make it as LDB launcher. I thought to fill the LDB tooltip at least with a missions report so I write something like this: Lua Code:
Now the problem. Is possible this make this addon MEMORY USAGE grows everytime I hover on the LDB ? Lua Code:
Should I use a frame with an event like: GARRISON_UPDATE To calc them and not the OnTooltipShow of the LDB ? Thanks to anyone. |
Answer to your first question, it is possible. Local variables are not deleted right away, a method to get around it is to declare the function with the variables inline and simply use them from there. It, I believe, reserves the location in memory allocating it only once and will be garbage collected eventually without creating excessive copies.
Answer to your second question, yes as that is best practice. But it would also help if globals are scoped properly as it can cause some minor issues that slowly stack. This has resulted in both Blizzard developers, and addon authors, creating stack overflows. Lua Code:
|
Why not declare "local mis_avl, mis_pro, mis_fin" in line 5 after "local GetCompleteMissions = C_Garrison.GetCompleteMissions", and don't call dataobj.OnTooltipShow with extra variables? Should be a bit larger average but smaller peak memory consumption.
|
... and the worst as to come :)
When I click to open the Draenor or Legion Hall panel I got: Is possible that addon is charged of all the memory used by the blizzard panel ? After a while I closed the panel I got: So the usage is returned low. Now I ask ... Is it a normal or expected behaviour ? :) Thanks to all. |
Quote:
Thanks for the reply. |
Just my two cents in on the topic. With Blizzard's recent obsession over rewriting APIs into returning tables, the inherent problem in doing so is it can easily turn into a memory hog. The two most expensive value types in Lua are functions and tables. In your function, you're requesting 3 different tables from such APIs. Even though you're only getting their length, Lua still allocated the memory to store them and they continue to wait for a garbage collection cycle to pick them up. It doesn't matter if you didn't store them in a variable, they existed for the moment they were used in an expression and therefore still take up space in memory until Lua gets rid of them later.
|
I meant something like
Lua Code:
|
Quote:
|
Lua Code:
|
Thanks to all for the kind replies.
Now I have collected all your inputs and this is the final (actual ? :) ) code: Lua Code:
Using a frame to collect data basing on events surely helped in decreasing the memory allocated ... even if it grows a lot the same when you click to get the panels but I think it can't be avoided :) Thanks again. |
Using table[somevar] = "something" is great for accessing unknown table keys. If you know the key you want to use you can access it with dot notation table.key = "something"
Example in your case: Lua Code:
Lua Code:
Just an FYI. Then again, I dislike wasting keystrokes like using brackets around if statements or ending lines with semicolons etc. ;). |
All times are GMT -6. The time now is 09:07 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI