Index: /trunk/include/VBox/com/ptr.h
===================================================================
--- /trunk/include/VBox/com/ptr.h	(revision 22699)
+++ /trunk/include/VBox/com/ptr.h	(revision 22700)
@@ -67,4 +67,10 @@
 #include <VBox/com/assert.h>
 
+namespace com
+{
+    #define LOGREF(pObj, cRefs) com::LogRef(#pObj "{%p}.refCnt=%d\n", (pObj), (cRefs));
+    void LogRef(const char *pcszFormat, ...);
+}
+
 /**
  *  Strong referencing operators. Used as a second argument to ComPtr<>/ComObjPtr<>.
@@ -75,6 +81,13 @@
 protected:
 
-    static void addref (C *p) { p->AddRef(); }
-    static void release (C *p) { p->Release(); }
+    static void addref(C *p)
+    {
+        size_t cRefs = p->AddRef();
+        LOGREF(p, cRefs);
+    }
+    static void release(C *p)
+    {
+        p->Release();
+    }
 };
 
Index: /trunk/include/iprt/log.h
===================================================================
--- /trunk/include/iprt/log.h	(revision 22699)
+++ /trunk/include/iprt/log.h	(revision 22700)
@@ -402,6 +402,8 @@
     /** aleksey logging. */
     RTLOGGRPFLAGS_ALEKSEY      = 0x00020000,
+    /** dj logging. */
+    RTLOGGRPFLAGS_DJ           = 0x00040000,
     /** NoName logging. */
-    RTLOGGRPFLAGS_NONAME       = 0x00040000
+    RTLOGGRPFLAGS_NONAME       = 0x00080000
 } RTLOGGRPFLAGS;
 
@@ -612,9 +614,13 @@
 #define LogAleksey(a)   LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_ALEKSEY,  LOG_GROUP, a)
 
+/** @def LogDJ
+ * dj logging.
+ */
+#define LogDJ(a)        LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_DJ,  LOG_GROUP, a)
+
 /** @def LogNoName
  * NoName logging.
  */
 #define LogNoName(a)    LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_NONAME,   LOG_GROUP, a)
-
 
 /** @def LogWarning
Index: /trunk/include/iprt/xml_cpp.h
===================================================================
--- /trunk/include/iprt/xml_cpp.h	(revision 22699)
+++ /trunk/include/iprt/xml_cpp.h	(revision 22700)
@@ -33,5 +33,5 @@
 #ifndef IN_RING3
 # error "There are no XML APIs available in Ring-0 Context!"
-#else /* IN_RING3 */
+#endif
 
 #include <list>
@@ -649,6 +649,4 @@
 #endif
 
-#endif /* IN_RING3 */
-
 /** @} */
 
Index: /trunk/src/VBox/Main/glue/com.cpp
===================================================================
--- /trunk/src/VBox/Main/glue/com.cpp	(revision 22699)
+++ /trunk/src/VBox/Main/glue/com.cpp	(revision 22700)
@@ -48,4 +48,5 @@
 #include <iprt/env.h>
 #include <iprt/string.h>
+#include <iprt/log.h>
 
 #include <VBox/err.h>
@@ -201,3 +202,19 @@
 #endif /* (VBOX_WITH_XPCOM) */
 
+/**
+ * Used by ComPtr and friends to log details about reference counting.
+ * @param pcszFormat
+ */
+void LogRef(const char *pcszFormat, ...)
+{
+    va_list va;
+    va_start(va, pcszFormat);
+    va_end(va);
+
+    char *psz = NULL;
+    RTStrAPrintfV(&psz, pcszFormat, va);
+    LogDJ((psz));
+    RTStrFree(psz);
+}
+
 } /* namespace com */
Index: /trunk/src/VBox/Runtime/common/log/log.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/log/log.cpp	(revision 22699)
+++ /trunk/src/VBox/Runtime/common/log/log.cpp	(revision 22700)
@@ -1175,4 +1175,5 @@
             { "bird",       RTLOGGRPFLAGS_BIRD },
             { "aleksey",    RTLOGGRPFLAGS_ALEKSEY },
+            { "dj",         RTLOGGRPFLAGS_DJ },
             { "n",          RTLOGGRPFLAGS_NONAME },
             { "noname",     RTLOGGRPFLAGS_NONAME }
