Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Tiberian Technologies / Blackhand Studios » Tiberian Technologies Forum » Possibly memory leak SSGM
Re: Possibly memory leak SSGM [message #487466 is a reply to message #487464] Fri, 02 May 2014 03:43 Go to previous messageGo to previous message
Neijwiert is currently offline  Neijwiert
Messages: 124
Registered: October 2009
Karma:
Recruit
danpaul88 wrote on Fri, 02 May 2014 02:20

SimpleDynVec stores all objects in a shared block of allocated memory, thus that usage of memmove is perfectly fine, the location it was moved from is inside the same block of allocated memory which will be reused when the next thing is added to the vector. It's a common pattern used to avoid allocating blocks of memory too frequently, std::vector does the same sort of thing. Don't confuse deleting something from the vector (removing the pointer to the struct from the vector) and freeing the memory allocated for the struct, they are two distinct operations which do different things.


You are however correct that the new'd instance of the Connection struct appears to be leaked on line 78 ( Connections.Delete(Connections[i]); ). Technically it is also leaked in Shutdown() but that is only called when the FDS is shutting down so it's not a massive problem although should be fixed for consistency.

Note it is NOT necessary to call Delete on the actual vector in shutdown() because the vector will erase itself when it goes out of scope (which occurs when the class instance which owns it is deconstructed), although it would perhaps be good practice to call Delete_All on the vector after looping through closing all the sockets just to avoid leaving dead sockets in the vector


Ok was just making sure. Atleast I learn something from it Smile
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Commands->Select_Weapon doesn't work clientside.
Next Topic: Quick brenbot question.
Goto Forum:
  


Current Time: Sat Sep 21 19:48:16 MST 2024

Total time taken to generate the page: 0.00671 seconds