Anybody knows a way to find memory leaks in a Delphi for Linux app? Is an command line app running on Windows 32 with no memory leaks. Compiled for Linux 64 bits and have a lot of memory leaks (memory on my server raises for ever).

Anybody knows a way to find memory leaks in a Delphi for Linux app? Is an command line app running on Windows 32 with no memory leaks. Compiled for Linux 64 bits and have a lot of memory leaks (memory on my server raises for ever).

Have no idea if is a problem on some library or one on the compiler. How to check? We dont have Fastmm4 on Linux, sadly.

Thanks for any help.

Comments

  1. Did you address the differences between the Linux ARC compiler and the Windows compiler which does not use ARC?

    Also, https://bitbucket.org/shadow_cs/delphi-leakcheck

    ReplyDelete
  2. You could use the Valgrind memory leak check :)

    ReplyDelete
  3. David Heffernan I believe yes, the only relevant was disposeOf and free. Any other details ? Can you share?

    ReplyDelete
  4. Horácio Filho Can please detail how to see in my source code the leaks reported by valgrind? I cant find that info.

    ReplyDelete
  5. German Gentile No that is not the only relevant thing. You also need to find strong reference cycles and mark non-owning references as [weak] or [unsafe] to break the cycle.

    Think of parent-child relationship. Parent owns a child, but if child has reference to parent that reference will create reference cycle if it is not marked as weak.

    Whether you will use [weak] or [unsafe] attribute depends on whether child (in this example) can outlive the parent. If it can then you must use [weak] or have some other mechanism to notify the child to set parent to nil - to avoid accessing dangling pointer. If the child cannot outlive the parent you can use [unsafe] as [weak] references must be tracked and have runtime overhead.

    ReplyDelete
  6. Thanks Dalija. Sorry to my quick post. I already double check and theres no reference cycles, that was what i mean. Best regards!

    ReplyDelete
  7. Hello German Gentile, for sure :)

    Run this command on a terminal instance:
    valgrind --tool=memcheck --gen-suppressions=all --leak-check=full --leak-resolution=high --track-origins=yes ./[your_project]

    That is going to generate a heap summary, call stacks without and with mangled symbols (following the Itanium C++ ABI) and a leak summary. Please, take a look at the call stacks in order to know where the memory leaks happened :)

    ReplyDelete
  8. Anonymous methods can also create cycles.

    And you also need to nil the reference after you call DisposeOf - not local ones that go out of scope soon. If the reference is just Disposed and not niled its memory will not be released until it goes out of scope.

    ReplyDelete
  9. Horácio Filho I cant get how can be traslated to delphi sources.Thanks anyway for your help.

    ReplyDelete
  10. David Heffernan I try delphi leakcheck but seems like is not ready for linux? It builds and run fine, but the report assume every single object on my code as a memory leak, even a lot of unistrings. Example:
    Leak detected 00000000024455E0 size 32 B for UnicodeString {RefCount: 1} = db_name
    Leak detected 0000000002444CE0 size 72 B for UnicodeString {RefCount: 1} = qyestadisticas_dbtable_name
    Leak detected 0000000002445A70 size 448 B
    I really wondered how much people is using linux delphi compiler. Maybe a bug in the compiler?

    ReplyDelete
  11. German Gentile There is no bug in the compiler. But if the object that leaks has string fields, those strings will also leak.

    ReplyDelete
  12. If you've double checked this, and there are no problem, why are there leaks?

    ReplyDelete
  13. David Heffernan As i say, my options are libraries (thirdy party) or compiler. Dalija say no bug on linux compiler so must be the libraries. No hope.

    ReplyDelete
  14. I used XCode tools for iOS to see memory leaks.
    If we had Win 32 ARC compiler...

    ReplyDelete
  15. OK, i get the Dalija book now. Im sure theres a lot to check before continue. Best regards and thanks to all!

    ReplyDelete
  16. German Gentile I hope it will be helpful. Yes, there is a lot to check. It may be harder at the beginning, but once you get deeper you will start noticing suspicious places and patterns more easily.

    For start, if you are overwhelmed with a lot of leaks, there is rather dumb, but pretty effective method to check whether something leaks or not.

    Pick a class you suspect and override its FreeInstance method and if it is not called, you have a leak.

    dalijap.blogspot.com - Is it leaking or not?

    ReplyDelete
  17. German Gentile You don't think that there might be bugs in your code?

    ReplyDelete
  18. David Heffernan I think not, but maybe yes.I must do a deeper check, for that reason i will read Dalija Prasnikar book and prepare to explore in depth.

    ReplyDelete
  19. David Heffernan Can use just a subset under linux. I need to genearte at runtime after call some functions a report but is not support under linux. Also as theres not map on linux the result is unusable.

    ReplyDelete
  20. German Gentile Prepare for a fun ride! We found memory leaks in most third party libraries and even in many of the core Delphi libraries like TTask... I would suggest the only real way to test big applications is to start by just making a simple test unit that creates and destroys each of the components you use i.e. TpgQuery.create() etc and see how memory looks after that (you might want to put them in a 100000 loop to show numbers big enough to detect easily) - at least that will test through a fair bit of the third party code quickly and then you can start doing the same with your blocks once you know the third parties are good.

    ReplyDelete

Post a Comment