User:Mook:Leak Notes

From MozillaWiki
Jump to: navigation, search

Notes about leak testing go here.

Environment variables

  • XPCOM_MEM_LEAK_LOG=file name
    • dumps a table of leaked (C++) objects to file on shutdown.
  • XPCOM_MEM_BLOAT_LOG=file name
    • dumps a table of all objects ever used to file on shutdown. Overrides XPCOM_MEM_LEAK_LOG if set.
  • XPCOM_MEM_REFCNT_LOG=file name
    • logs all AddRef / Release of a given class. Use with XPCOM_MEM_LOG_CLASSES, otherwise too much output basically crashes the system.
  • XPCOM_MEM_LOG_CLASSES=class1,class2...
    • log only the given classes into XPCOM_MEM_REFCNT_LOG
  • XPCOM_MEM_LOG_OBJECTS=serial1,serial2...
    • log only objects with the given serial number (as output by previous refcnt logs). Good luck getting things deterministic enough for this to be useful.

mozilla.org has more stuff, but they do not seem to be as useful (on Win32).

Scripts (for refcnt logs)

  1. Run the target app with XPCOM_MEM_REFCNT_LOG to generate data to look at.
  2. Run find-leakers.pl < file to find the addresses of the leaked objects.
  3. Run make-tree.pl --object address --ignore-balanced < file > output file to build a tree of the allocations to stare at. Note that here might get confused if the lines have DOS-style line endings.

Notes on the tree generated

  • On createInstance calls, it's shown as AddRef / AddRef / Release with the first and third being a temporary nsCOMPtr<nsISupports> that can be discarded.

TODO: see if I can paste the leak script I'm using.