   trivial garbage collection question
  Is gc more efficient than manual use of new/delete?   
Quote:Original post by MakaanIs gc more efficient than manual use of new/delete?This is not a trivial question. The answer depends on what kind of efficient you mean and how both methods are implemented and used.   ;  By efficient i mean speed.i know that gc uses more memory for tracking data, so memory efficiency over new/delete is out of the question.   ;Quote:Original post by MakaanBy efficient i mean speed.i know that gc uses more memory for tracking data, so memory efficiency over new/delete is out of the question.Ok. It still depends on how both methods are implemented and used.I'll assume that by speed you mean runtime performance, not development speed, that we're talking about game development, since we are on gamedev.net, and that you have a suitable implementation of both methods. Initially, gc will be faster, because it doesn't have to deallocate anything. Once memory gets tight, the gc will have to run more frequently, somewhat diminishing the advantages of the lazy deallocations.So, in conclusion, the less memory you have free, the more beneficial manual memory management gets. And that's frequently the case in gamedev. Gc may also perform defragmentation, but you can have that with manual memory management too, so that's not really an advantage, except that its cost may be hidden by the cost of each gc sweep.The most efficient method btw, is to avoid dynamic memory allocation and deallocation as much as possible.   ;Quote:Original post by RattenhirnThe most efficient method btw, is to avoid dynamic memory allocation and deallocation as much as possible.QFT. Whilst it's sometimes unobtainable, your goal should be to make no dynamic allocations at all whilst the gameplay is running. By all means do whatever you need when loading and initialising a level, but once it's started don't do any more.All allocations/frees are slow and at the end of the day you shouldn't really need to make any on the fly. (Pool allocators are a good solution for stuff that has to be a bit dynamic)You can get away with murder if you're targetting PC only, but its a good habit to get into to make things the way they should be made imo.   ;  It's possible for GC allocations to be faster than "traditional new", but I'd guess that "traditional delete" is faster than gc.Collect().   