EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   General::General Discussion (https://www.eqemulator.org/forums/forumdisplay.php?f=586)
-   -   Memory Leaks (https://www.eqemulator.org/forums/showthread.php?t=35671)

Uleat 08-17-2012 02:31 AM

Memory Leaks
 
Are there more issues with memory leaks with one OS over another when running the EQEmu server?


I see where most type instances are safe_delete()'d in one way or another, but there are cases where they are not.

I know Windows has the GC that should reclaim orphaned resources, but wasn't sure if Linux did the same.

lerxst2112 08-17-2012 03:45 AM

C++ is not a garbage collected language. (1) If memory is allocated and deallocated the allocator can do what it wishes with the free memory. It is not required to, and in many cases will not, reduce the size of the heap as far as any monitoring tools can see and this does not mean there is a leak. The only guarantee is that all memory, allocated or free, will be released to the operating system when the program terminates.

The safe_delete macros aren't all that exciting. They check for a non-null pointer when it's perfectly safe to delete a null pointer, and setting the pointer to null afterward is only useful if the pointer is going to be reused and the code that reuses it actually examines the pointer before allocating the new memory. RAII and smart pointer are a much safer way to manage dynamic memory.

1. Memory allocator replacements that function as a garbage collector are available, but the emulator doesn't use them. I've been programming a long time and I've never seen them used.

Uleat 08-17-2012 07:44 AM

That's good to know. Thanks for the explanation!

I guess I should really sit down sometime and actually learn c/c++.

image 08-21-2012 11:26 AM

safe_delete is just checking to see if the pointer we pass in isn't null. If it isn't we delete it. Nothing special there. Why is there so much concern posed at memory leaks anyway?

Uleat 08-21-2012 09:19 PM

Curiosity on my behalf. I remember reading about some mem leaks in a very old post.

Since I am making changes and am not very familiar with c++, I just wanted to make sure anything that I add
doesn't create new ones.

lerxst2112 08-21-2012 10:46 PM

If you allocate memory, delete it when you're done with it. No leaks, just like magic.

boduzapho 08-22-2012 12:13 PM

BUT BE careful, an old friend told the the difference between C# and C++ is, if you screw up in C# its like getting a paper cut, if you do it in C++ it's like a shotgun blowing your leg off. - Happy Programming!


All times are GMT -4. The time now is 08:21 AM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.