Go Back   EQEmulator Home > EQEmulator Forums > General > General::General Discussion

General::General Discussion General discussion about EverQuest(tm), EQEMu, and related topics.
Do not post support topics here.

Reply
 
Thread Tools Display Modes
  #1  
Old 08-17-2012, 02:31 AM
Uleat's Avatar
Uleat
Developer
 
Join Date: Apr 2012
Location: North Carolina
Posts: 2,815
Default 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.
__________________
Uleat of Bertoxxulous

Compilin' Dirty
Reply With Quote
  #2  
Old 08-17-2012, 03:45 AM
lerxst2112
Demi-God
 
Join Date: Aug 2010
Posts: 1,742
Default

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.
Reply With Quote
  #3  
Old 08-17-2012, 07:44 AM
Uleat's Avatar
Uleat
Developer
 
Join Date: Apr 2012
Location: North Carolina
Posts: 2,815
Default

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

I guess I should really sit down sometime and actually learn c/c++.
__________________
Uleat of Bertoxxulous

Compilin' Dirty
Reply With Quote
  #4  
Old 08-21-2012, 11:26 AM
image
Demi-God
 
Join Date: Jan 2002
Posts: 1,290
Default

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?
__________________
www.eq2emu.com
EQ2Emu Developer
Former EQEMu Developer / GuildWars / Zek Seasons Servers
Member of the "I hate devn00b" club.
Reply With Quote
  #5  
Old 08-21-2012, 09:19 PM
Uleat's Avatar
Uleat
Developer
 
Join Date: Apr 2012
Location: North Carolina
Posts: 2,815
Default

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.
__________________
Uleat of Bertoxxulous

Compilin' Dirty
Reply With Quote
  #6  
Old 08-21-2012, 10:46 PM
lerxst2112
Demi-God
 
Join Date: Aug 2010
Posts: 1,742
Default

If you allocate memory, delete it when you're done with it. No leaks, just like magic.
Reply With Quote
  #7  
Old 08-22-2012, 12:13 PM
boduzapho
Fire Beetle
 
Join Date: Aug 2012
Location: United States
Posts: 8
Default

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!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 01:06 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3