Addon Memory Usage

Hello,
My addon seems to be constantly using memory. I assumed I have some type of memory leak somewhere.

I decided to rewrite my addon. I thought, “Instead of writing code for the xp and rep bars, why not just hook the functions, then add my code.” On Enter, my bar displays the rep values for all the factions in the current version (Shadowlands)

If I use hooksecurefunc and call for update, it will print my test message, when the bar text is updated.
I want to be able to hook on the OnEnter item. Is that possible? It doesn’t work for me.

hooksecurefunc(ReputationBarMixin, “Update”, function(self)
print(“Works”)
end)

But, this does nothing. No errors, nothing.

hooksecurefunc(ReputationBarMixin, “OnEnter”, function(self)
print(“Works”)
end)

Can you only hook certain calls for an item? If so, is there a way to know you can’t hook a specific function, and it’s not just me messing up? :slight_smile:

Thank you,
Mike

Mixins are used to inherit methods and properties (functions and variables) onto frames (one mixin function could be called from multiple frames).

ReputationBarMixin is use by the ReputationStatusBarTemplate so that any frame that inherits that template also inherits the ReputationBarMixin information.

That’s the frame you want to hook or your mixin hooks might get triggerd by frames you’re not interested in.

StatusTrackingBarManager adds a bar that inherits the ReputationStatusBarTemplate and places it first in the StatusTrackingBarManage.bars table.

hooksecurefunc(StatusTrackingBarManager.bars[1], "Update", function(self)
   print(self, "Update")
end)

The OnEnter method is assigned to the OnEnter script but you can just hook the script itself

StatusTrackingBarManager.bars[1]:HookScript("OnEnter", function(self)
   print(self, "OnEnter")
end)
1 Like

Thank you for the explanation.
I tried the “StatusTrackingBarManager”, but I didn’t look for the .bars item, so that did not work for me. And now I know why.

Update:

I don’t know if I am doing something wrong, or my WoW is messed up, or what. “Scan and Repair” finds no problems.

I have vanilla WoW running, with just my addon. The addon contains the following code, only.

StatusTrackingBarManager.bars[1]:HookScript(“OnEnter”, function(self)
print(self, “OnEnter”)
end)

for k,v in pairs(StatusTrackingBarManager) do
if k == “bars” then
print(k,v, type(v))
for x,y in pairs(v) do
print("SBTM: ",x,y)
end
end
end

And the first item returns an error:
attempt to index field '?' (a nil value)

And if I comment out the first item, the second item only recognizes the print(k,v,type(v)) and it is like the 2nd pairs loop for the pairs(v) doesn’t even exist (it doesn’t execute)

And, it didn’t recognize pairs(StatusTrackingBarManager.bars[1]) as valid item. But when I print pairs(StatusTrackingBarManager) that will display all the items contained in that table. Including " bars table 0022…"

StatusTrackingBarManager:HookScript("OnEnter", function(self)
    print("Currently there are " .. self:GetNumberVisibleBars() .. " bars showing")
    for i, bar in ipairs(self.bars) do
        if(bar:ShouldBeVisible()) then
            print(bar.OverlayFrame.Text:GetText(), bar:IsShown())
        end
    end
end)

On my lvl 60 main, I get one of the following:

Currently there are 0 bars showing

or

Currently there are 1 bars showing
Bloodsail Buccaneers 22100 / 36000 true

1 Like

bars is an array of all the bars that could be shown by the status bar manager. Only 1 or 2 of these are ever shown at a time, and sometimes it picks 2 when 3 or more could appear.

Example: in BFA it would choose between azerite, xp and rep.

1 Like