Does FastMM detect all memory leaks

懵懂的女人 提交于 2019-11-30 15:33:42

No, only memory leaks which memory was alocated by FastMM.

EDIT: Maybe the answer looks wrapped but it is not! If anyone check the FastMM haw is made than can see that every pointer of memory alocation is pushed (and poped out at FreeMem) in to one of stacks (there is more stacks, depend of memory size) so at the end of closing application the FastMM only check stacks, if something in stacks, and if it is, than report memory leak!

FastMM is a layer on top of Windows memory management. Obviously, if you (or some component or whatever) uses Windows APIs to allocate memory, then such allocation bypasses FastMM and you won't be able to track it. BTW Delphi memory managers themselves use that APIs to allocate chunks of memory. So if you need to see allocations on that level, FastMM is not enough - you must use tools like AQTime and similar (as I suggested in the previous question).

I've never known FastMM to fail to detect a memory leak.

There are several possible causes: (which apply to any memory manager)

  • your main program loop leaks memory, but does so to something that is freed on shutdown
    • the simplest case is logging to a memo. The memo gets bigger and bigger, but is destroyed on shutdown.
  • the memory is allocated outside fastmm's control
    • directly allocating from windows
    • memory allocated in dlls etc.
  • Heapfragmentation. A memory manager keeps large blocks allocated (e.g. because it still contains a small % of allocations). Result: The app doesn't use it, but it is not release to the OS either. The runtime/memorymanager keeps it around.
    • fastmm should be more resilient against this phenomena, but in doubt try to print heapmanager info to see if this is the case.

There is a lot of good answer already, but one point that wasn't mentionned yet...

There is a lot of "leaks" that won't get detected by most memory leak detector since the memory IS freed, but way after it isn't used anymore. For exemple, object stacked in a TObjectList. Object are put in the object list, but after you are done using them, you don't free them. They will be destroyed when the object list is destroyed too (When application close for exemple, assuming OwnsObject=True). Since the objects are actually freed, objects are not "leaked", but still make your application use more and more memory over time.

FastMM won't report those as it only makes "full run" analysis. To detect those, you need a memory leak detector that allows to do partial runs, that is, analyzing what "leaked" between point A and point B during the execution. AQTime that Eugene mentionned allow that kind of checks. But be aware that is takes a bit of analysis because that will yield many false-positive (Pretty much all "realloc" operations will be marked as a leak).

Jeroen Wiert Pluimers

FastMM does not detect leaks of memory allocations not going through FastMM.

This can include GlobalAlloc calls from 3rd party libraries or DLLs you use.
Edit: Microsoft's MSDN has a nice list of memory allocation methods.

This was in fact the problem I mentioned I mentioned in my answer to your previous FastMM question.

You can use a tool like VMMap to track the memory leaks that FastMM cannot detect.

--jeroen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!