Date: Wed, 26 Apr 1995 13:26:09 -0400 From: kagel AT quasar DOT bloomberg DOT com To: B DOT S DOT Runnacles AT soton DOT ac DOT uk Cc: djgpp AT sun DOT soe DOT clarkson DOT edu Subject: Re: Unable to free memory.. Reply-To: kagel AT ts1 DOT bloomberg DOT com Date: Wed, 26 Apr 1995 15:03:58 +0100 (BST) From: "B.S.Runnacles" Dear all.... I have this bit of (schematic) code that frees the memory used in a linked list: LinkedList::~LinkedList(void) { listnode *Root,*Current; // a data structure with next pointer and data _go32_dpmi_meminfo info1,info2; for (Current = Root; Current != NULL; Current = Current->next) { _go32_dpmi_get_free_memory_information(&info1); delete Current; _go32_dpmi_get_free_memory_information(&info2); cout << info2.available_memory - info1.available_memory << endl; } } But the result says that there is no difference in the free memory before and after the delete call. Has anyone got any ideas as to why? I may be doing something fundementally wrong here, any hints would be nice. I think the memory isn't being freed because after a few hundred iterations the code falls over complaining of a full swap file. Ben Runnacles Image, Speech and Intelligent Systems Group University of Southampton, UK. OK, here's what is going on: 1) Memory freed is only freed to malloc's free block data structure not back to the OS or to go32 so _go32_dpmi_get_free_memory_information does not know about it. 2) Other allocations intermixed with the ones you have freed are fragmenting memory so that it cannot be reused. Thus after "a few hundred iterations" the code fails. This looks like the most likely scenario. -- Art S. Kagel, kagel AT ts1 DOT bloomberg DOT com