• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Does "Replace Unit" cause a memory leak?

Status
Not open for further replies.
Level 11
Joined
Aug 11, 2009
Messages
594
As stated in title, does the "Replace Unit" function in trigger cause a memory leak? If so, is there any easy way to fix it or is it better to just not use it at all?

Im adding units to a marketplace from a random pool of over 60 units so instead of removing every singel unit type when refreshing the marketplace, i just replace the marketplace with a new one. Maybe thats a bad idea.

Thanks in advance :)
 
Level 18
Joined
Jan 1, 2018
Messages
728
The thread that Strydhaizer linked said:
A unit will always keep a tiny bit of memory, even when removed properly. 0.04 kb and unpreventable.
And since ReplaceUnit creates a new unit, the answer is yes.
 
Level 11
Joined
Aug 11, 2009
Messages
594
Thank you for your answers. I am not very knowledgable about leaks. Would around 800 Replace Unit functions result in the map being laggy?
Thinking the marketplace might refresh a maximum of 100 times per player during a full playthrough and a total of 8 players.

If you dont know its ok, i will keep it as it is and see through testing if its a problem or not :)
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
Would around 800 Replace Unit functions result in the map being laggy?
Such a low number won't cause a problem (but if all replacements occur at the same time, you may feel a spike depending on your computer specs), the leak that is mentioned above is very minor you won't feel it before thousands of unit creation/removing.

Also you can test such stuff yourself. Just open your task manager and note memory usage, replace N amount of units and wait for a while (W3 does not immediately clear unused memory so waiting is crucial, it will start going down after a while), then compare memory usages. Try not doing anything else though, even moving your camera from one point to another increases memory usage temporarily so you may misjudge the result.
 
Last edited:
Thank you for your answers. I am not very knowledgable about leaks. Would around 800 Replace Unit functions result in the map being laggy?
Thinking the marketplace might refresh a maximum of 100 times per player during a full playthrough and a total of 8 players.

If you dont know its ok, i will keep it as it is and see through testing if its a problem or not :)

Yes, you're technically creating 800 new units in your map every time you 'refresh', even if you have only 100 units created at a single second you will already notice game stutter/heavy performance hit.
 
Level 39
Joined
Feb 27, 2007
Messages
5,010
The actual issue with Replace Unit is that it has a reference leak. Look at the JASS function and you will see it declares a local unit variable that isn’t nulled before the function returns. There is nothing you can do about this in GUI and you will likely not notice this.
 
Status
Not open for further replies.
Top