diff --git a/gst/gstobject.c b/gst/gstobject.c
index fabfa0e..78f626e 100644
--- a/gst/gstobject.c
+++ b/gst/gstobject.c
@@ -90,6 +90,8 @@
 #include "gstinfo.h"
 #include "gstutils.h"
 
+#include <execinfo.h>
+
 #ifndef GST_DISABLE_TRACE
 #include "gsttrace.h"
 static GstAllocTrace *_gst_object_trace;
@@ -285,6 +287,8 @@ gst_object_init (GstObject * object)
  *
  * Returns: A pointer to @object
  */
+static const char *_gst_refcount_backtrace_object = "identity0";
+
 gpointer
 gst_object_ref (gpointer object)
 {
@@ -295,6 +299,25 @@ gst_object_ref (gpointer object)
       object,
       ((GObject *) object)->ref_count, ((GObject *) object)->ref_count + 1);
 #endif
+  if (_gst_refcount_backtrace_object && ((GstObject *)object)->name &&
+      strcmp (((GstObject *)object)->name, _gst_refcount_backtrace_object) == 0) {
+    int i;
+    void *bt[128];
+    int bt_size;
+    char **strings;
+
+    fprintf(stderr, "REF: object %s ref %d -> %d\n",
+        _gst_refcount_backtrace_object, ((GObject *) object)->ref_count,
+        ((GObject *) object)->ref_count + 1);
+
+    bt_size = backtrace(bt, sizeof(bt) / sizeof(void *));
+    strings = backtrace_symbols (bt, bt_size);
+    /* skip 0, since it's always this function */
+    for (i = 1; i < MIN(bt_size, 6); i++) {
+      fprintf(stderr, "  [%d]: %s\n", i, strings[i]);
+    }
+    free(strings);
+  }
   g_object_ref (object);
 
   return object;
@@ -322,6 +345,25 @@ gst_object_unref (gpointer object)
       object,
       ((GObject *) object)->ref_count, ((GObject *) object)->ref_count - 1);
 #endif
+  if (_gst_refcount_backtrace_object && ((GstObject *)object)->name &&
+      strcmp (((GstObject *)object)->name, _gst_refcount_backtrace_object) == 0) {
+    int i;
+    void *bt[128];
+    int bt_size;
+    char **strings;
+
+    fprintf(stderr, "UNREF: object %s unref %d -> %d\n",
+        _gst_refcount_backtrace_object, ((GObject *) object)->ref_count,
+        ((GObject *) object)->ref_count - 1);
+
+    bt_size = backtrace(bt, sizeof(bt) / sizeof(void *));
+    strings = backtrace_symbols (bt, bt_size);
+    /* skip 0, since it's always this function */
+    for (i = 1; i < MIN(bt_size, 6); i++) {
+      fprintf(stderr, "  [%d]: %s\n", i, strings[i]);
+    }
+    free(strings);
+  }
   g_object_unref (object);
 }
 
