diff --git a/src/backend.c b/src/backend.c
index 6e051408b9c1b11f0bd54b308be71c34f7a750e0..2edc3ffdad980a2bd6d18280fb54405b5a05b35d 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -4,7 +4,7 @@
 ||| See the files COPYING and DISCLAIMER for more information.
 \*/
 #include "global.h"
-RCSID("$Id: backend.c,v 1.25 1998/03/25 23:15:35 grubba Exp $");
+RCSID("$Id: backend.c,v 1.26 1998/04/06 04:15:12 hubbe Exp $");
 #include "fdlib.h"
 #include "backend.h"
 #include <errno.h>
@@ -462,6 +462,7 @@ void do_debug(void)
   extern void check_all_objects(void);
   extern void verify_shared_strings_tables(void);
   extern void slow_check_stack(void);
+  extern void do_gc(void);
 
   slow_check_stack();
   check_all_arrays();
@@ -519,6 +520,8 @@ void do_debug(void)
     }
   }
 #endif
+
+  if(d_flag>3) do_gc();
 }
 #endif
 
diff --git a/src/dmalloc.h b/src/dmalloc.h
index 57883728fc44de849c119f4614d86ff92c43f167..2d17ab556eb2f435f7f88a41e7c0467ea491ec3a 100644
--- a/src/dmalloc.h
+++ b/src/dmalloc.h
@@ -1,5 +1,5 @@
 /*
- * $Id: dmalloc.h,v 1.5 1998/03/28 15:03:54 grubba Exp $
+ * $Id: dmalloc.h,v 1.6 1998/04/06 04:20:42 hubbe Exp $
  */
 #ifdef DEBUG_MALLOC
 
@@ -31,7 +31,9 @@ void *debug_malloc_update_location(void *,const char *, int);
 #define debug_malloc_touch(X) debug_malloc_update_location((X),__FILE__,__LINE__)
 #define debug_malloc_pass(X) debug_malloc_update_location((X),__FILE__,__LINE__)
 #define xalloc(X) ((char *)debug_malloc_touch(debug_xalloc(X)))
+void debug_malloc_dump_references(void *x);
 #else
+#define debug_malloc_dump_references(X)
 #define xalloc debug_xalloc
 #define dbm_main main
 #define DO_IF_DMALLOC(X)
diff --git a/src/gc.c b/src/gc.c
index 9ad862a62dadfa14ddfb502d661f87d4b8d41f21..e5261f8fe5d22da0a807255b7c15e47992dcb3b2 100644
--- a/src/gc.c
+++ b/src/gc.c
@@ -25,7 +25,7 @@ struct callback *gc_evaluator_callback=0;
 #include "main.h"
 #include <math.h>
 
-RCSID("$Id: gc.c,v 1.30 1998/03/28 15:31:05 grubba Exp $");
+RCSID("$Id: gc.c,v 1.31 1998/04/06 04:25:26 hubbe Exp $");
 
 /* Run garbage collect approximate every time we have
  * 20 percent of all arrays, objects and programs is
@@ -241,7 +241,7 @@ void describe_location(void *memblock, TYPE_T type, void *location)
 static void gdb_gc_stop_here(void *a)
 {
   fprintf(stderr,"***One ref found%s.\n",found_where);
-  describe_something(found_in, found_in_type);
+  describe_something(found_in, found_in_type, 0);
   describe_location(found_in, found_in_type, gc_svalue_location);
 }
 
@@ -286,10 +286,12 @@ int debug_gc_check(void *x, TYPE_T t, void *data)
   return ret;
 }
 
-void describe_something(void *a, int t)
+void describe_something(void *a, int t, int dm)
 {
   struct program *p=(struct program *)a;
   if(!a) return;
+  if(dm)
+    debug_malloc_dump_references(a);
   if(t==-1)
   {
     fprintf(stderr,"**Location description: %s\n",(char *)a);
@@ -304,6 +306,14 @@ void describe_something(void *a, int t)
   {
     case T_OBJECT:
       p=((struct object *)a)->prog;
+      fprintf(stderr,"**Parent identifier: %d\n",((struct object *)a)->parent_identifier);
+      if( ((struct object *)a)->parent)
+      {
+	fprintf(stderr,"**Describing object's parent:\n");
+	describe_something( ((struct object *)a)->parent, t, 1);
+      }else{
+	fprintf(stderr,"**There is no parent (any longer?)\n");
+      }
       if(!p)
       {
 	fprintf(stderr,"**The object is destructed.\n");
@@ -323,7 +333,7 @@ void describe_something(void *a, int t)
 	fprintf(stderr,"**The program was written in C.\n");
 	fprintf(stderr,"**identifiers:\n");
 	for(e=0;e<p->num_identifiers;e++)
-	  fprintf(stderr,"*** %s\n",p->identifiers[e].name->str);
+	  fprintf(stderr,"**** %s\n",p->identifiers[e].name->str);
       }
 
       for(pos=0;pos<(long)p->num_program && pos<100;pos++)
@@ -361,6 +371,12 @@ void describe_something(void *a, int t)
       break;
     }
   }
+  fprintf(stderr,"*******************\n");
+}
+
+void describe(void *x)
+{
+  describe_something(x, attempt_to_identify(x),1);
 }
 
 #endif
@@ -451,14 +467,15 @@ int gc_is_referenced(void *a)
   struct marker *m;
   m=getmark(a);
 #ifdef DEBUG
-  if(m->refs + m->xrefs > *(INT32 *)a)
+  if(m->refs + m->xrefs > *(INT32 *)a ||
+     (!(m->refs < *(INT32 *)a) && m->xrefs) )
   {
     INT32 refs=m->refs;
     INT32 xrefs=m->xrefs;
     TYPE_T t=attempt_to_identify(a);
 
     fprintf(stderr,"**Something has %ld references, while gc() found %ld + %ld external.\n",(long)*(INT32 *)a,(long)refs,(long)xrefs);
-    describe_something(a, t);
+    describe_something(a, t, 1);
 
     locate_references(a);
 
@@ -514,6 +531,24 @@ int gc_do_free(void *a)
 {
   struct marker *m;
   m=getmark(a);
+#ifdef DEBUG
+  if( !(m->flags & GC_REFERENCED)  && m->flags & GC_XREFERENCED )
+  {
+    INT32 refs=m->refs;
+    INT32 xrefs=m->xrefs;
+    TYPE_T t=attempt_to_identify(a);
+
+    fprintf(stderr,"**gc_is_referenced failed, object has %ld references, while gc() found %ld + %ld external.\n",(long)*(INT32 *)a,(long)refs,(long)xrefs);
+    describe_something(a, t, 1);
+
+    locate_references(a);
+
+    fatal("GC failed object (has %d, found %d + %d external)\n",
+	  *(INT32 *)a,
+	  refs,
+	  xrefs);
+  }
+#endif
   return !(m->flags & GC_REFERENCED);
 }
 
diff --git a/src/gc.h b/src/gc.h
index 22c6bc2fe8c17c44ccbb4c587cf68faa08f0e3b3..4e72c2f0bf4ddf0906c8ca774fcb894261e5b133 100644
--- a/src/gc.h
+++ b/src/gc.h
@@ -1,5 +1,5 @@
 /*
- * $Id: gc.h,v 1.16 1998/03/28 15:15:32 grubba Exp $
+ * $Id: gc.h,v 1.17 1998/04/06 04:25:27 hubbe Exp $
  */
 #ifndef GC_H
 #define GC_H
@@ -38,8 +38,10 @@ void debug_gc_xmark_svalues(struct svalue *s, int num, char *fromwhere);
 TYPE_FIELD debug_gc_check_svalues(struct svalue *s, int num, TYPE_T t, void *data);
 void debug_gc_check_short_svalue(union anything *u, TYPE_T type, TYPE_T t, void *data);
 int debug_gc_check(void *x, TYPE_T t, void *data);
-void describe_something(void *a, int t);
+void describe_something(void *a, int t, int dm);
+void describe(void *x);
 INT32 gc_check(void *a);
+void locate_references(void *a);
 int gc_is_referenced(void *a);
 int gc_external_mark(void *a);
 int gc_mark(void *a);
diff --git a/src/pike_memory.c b/src/pike_memory.c
index 1dcd1b7319bd171d12dc4c85ebcc22c127cb536d..cba84ca1c6c9383255f81d159f6b24ced1829fb5 100644
--- a/src/pike_memory.c
+++ b/src/pike_memory.c
@@ -7,8 +7,9 @@
 #include "pike_memory.h"
 #include "error.h"
 #include "pike_macros.h"
+#include "gc.h"
 
-RCSID("$Id: pike_memory.c,v 1.18 1998/03/28 15:05:23 grubba Exp $");
+RCSID("$Id: pike_memory.c,v 1.19 1998/04/06 04:29:27 hubbe Exp $");
 
 /* strdup() is used by several modules, so let's provide it */
 #ifndef HAVE_STRDUP
@@ -852,6 +853,11 @@ void dump_memhdr_locations(struct memhdr *from,
   }
 }
 
+void debug_malloc_dump_references(void *x)
+{
+  dump_memhdr_locations(find_memhdr(x),0);
+}
+
 void cleanup_memhdrs()
 {
   unsigned long h;
@@ -873,6 +879,9 @@ void cleanup_memhdrs()
 
 	
 	fprintf(stderr, "LEAK: (%p) %d bytes\n",m->data, m->size);
+#ifdef DEBUG
+	describe_something(m->data, attempt_to_identify(m->data),0);
+#endif
 	for(l=m->locations;l;l=l->next)
 	{
 	  struct fileloc *f=find_file_location(l->locnum);