05-08-15, 04:06 AM | #1 |
new Cast Bar AddOn stacking high on memory
Hi, I have been making a new cast bar mod and it seems to work fine but the memory consumption over time gets very high. It starts at 8kb in AddOn memory but when spamming casts such as at a Training dummy or healing myself, it keeps going up and eventually goes over 2MB - 3MB or even higher.
Is this normal for cast bars? I've been trying to analyse my code to find out the source of this. I thought maybe it was recursion of C_Timer.After calls but after trying to fix this, I don't think it is. I can post the code here but its long so if you want me to upload it somewhere I can do. I've also tried using a do-end block where the "constructor" is but I wasn't sure why the for loop couldn't call the reference to the function if I used it so I commented it out Lua Code:
If anyone wants a challenge to look into this that would be brilliant! I still have a lot of work to do with adding a latency bar etc.. but for now just want to get the basics fixed so its more efficient. Thank you! Also I called the template the "prototype" but I don't use metatables since I wanted to add the inherited functions to a widget and didn't want to mess with the widget's metatable (StatusBar). I hope it doesn't make the code confusing :S Last edited by Mayron : 05-08-15 at 04:09 AM. |
|
05-08-15, 04:36 AM | #2 |
Code:
C_Timer.After(0.01, function() self:FadeOut() end) Code:
C_Timer.After(0.01, function() self:UpdateCasting() end) I would say just use OnUpdate for the UpdateCasting bit and probably an animation for FadeOut. There's nothing inherently bad with OnUpdate, not at all. The new C_Timer functions I think are mostly suitable when the actual time is the significant variable.
__________________
Grab your sword and fight the Horde! |
|
05-08-15, 06:03 AM | #3 | |
Lua Code:
and used Lua Code:
instead.. Would this still be a big problem? Since it is no longer creating a new function each time but I was worried this would cause some sort of large recursive depth which would cause a new function to be opened inside of previous ones causing large memory usage. (not too sure about how Lua handles these types of things) But I completely agree that using an Animation Widget is much more practical. I just thought C_Timer.After was more efficient compared to OnUpdate from what I read about it a long time ago. Last edited by Mayron : 05-08-15 at 06:05 AM. |
||
05-08-15, 09:01 AM | #4 | |
Yes and no. In this case it could be just as efficient to use C_Timer.NewTicker, an OnUpdate hook, or an animation group. OnUpdate is only bad when used incorrectly like iterating over large tables or doing large operations on each frame.
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison |
||
05-08-15, 10:40 AM | #5 | |
C_Timer is probably better in certain scenarios, but I don't know that it will be better here. You're effectively using it as one would OnUpdate, running a script very frequently, and that script on its own is going to be the processing heavy bit as opposed to using OnUpdate vs C_Timer making a real difference. If you want to do something like "say hi after 3 seconds", then C_Timer is probably better, because the actual timer will run in C or some other lower level thing, rather than the logic being handled by Lua in a constantly executing script.
__________________
Grab your sword and fight the Horde! |
||
05-08-15, 12:56 PM | #6 |
Ah okay, thanks for clearing that up.
I ended up using OnUpdate because it was more convenient of a solution and used UIFrameFadeIn and UIFrameFadeOut functions rather than an animation since it means less code and I just wanted a simple fading effect. It saved me a lot of work. The memory usage is 139kb after a full session of casting till my mana was gone which I'm satisfied with. Thanks again! |
|
05-09-15, 03:32 AM | #7 |
Sounds good! UIFrameFadeIn and UIFrameFadeOut used to taint the talent frame (switching talents) or something though, no idea whether it still does. Might want to look into that. Have the functions run before you open the talent frame.
__________________
Grab your sword and fight the Horde! |
|
05-11-15, 04:39 PM | #8 |
Thanks for the heads up but nope it all seems to be working perfectly. Testing it thoroughly with no tainting issues
|
|
WoWInterface » Developer Discussions » Lua/XML Help » new Cast Bar AddOn stacking high on memory |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|