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 #487464 is a reply to message #487458] Fri, 02 May 2014 02:20 Go to previous messageGo to previous message
danpaul88 is currently offline  danpaul88
Messages: 5795
Registered: June 2004
Location: England
Karma:
General (5 Stars)
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


http://steamsignature.com/card/1/76561197975867233.png

[Updated on: Fri, 02 May 2014 02:23]

Report message to a moderator

 
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: Sun Dec 22 10:38:25 MST 2024

Total time taken to generate the page: 0.00621 seconds