🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #3557

Re: De-Allocating Memory?

#3557
From: Simon Raybould
Date: Wed, 09 May 1990 12:10
35 lines
1616 bytes
In article <12750@wpi.wpi.edu> pawn@wpi.wpi.edu (Kevin Goroway) writes:
>I think I need some quick tutoring as to how one deallocates memory:
>
>I'm doing an awful lot of mallocs to create a lot of linked lists...
>when I free them using
>Freeit(object)
>  struct obj *object;
>{
>	if (object->next != NULL)
>		Freeit(object->next);
>	free(object);
>}



You need a recursive routine to free the whole list, along the lines of

freelist(ptr)
struct listelement *ptr;
{
	if(ptr->Next)
		freelist(ptr->Next);	/* Recurse */
	if(ptr)
		free(ptr);
}



+-=-=-=-=-=-=-=-=-=-=-=-=-=-=+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
|   British Telecom Fulcrum  | name : Simon John Raybould   {^.^}   |
|   Fordrough Lane           | path : sie@fulcrum.bt.co.uk   \~/    |
|   Birmingham               +-----------+--------------------------|
|   B9 5LD                   |   //      | AMIGA B2000HD 3MB 8088BB |
|   ENGLAND                  | \X/AMIGA  | Lattice C V5.05          |
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=+=-=-=-=-=-=+=-=-=-=-=-=-=-=-=-=-=-=-=-+
Technical Details
Message-ID: <X-8#!|_@masalla.fulcrum.bt.co.uk>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!samsung!uunet!mcsun!ukc!axion!masalla.fulcrum.bt.co.uk!sie
References: <12750@wpi.wpi.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!samsung!uunet!mcsun!ukc!axion!masalla.fulcrum.bt.co.uk!sie
From: S.J.Raybould@fulcrum.bt.co.uk (Simon Raybould)
Newsgroups: comp.sys.amiga.tech
Subject: Re: De-Allocating Memory?
Keywords: Lattice 5.04?
Message-ID: <X-8#!|_@masalla.fulcrum.bt.co.uk>
Date: 9 May 90 12:10:28 GMT
References: <12750@wpi.wpi.edu>
Organization: BT Fulcrum, Birmingham, England
Lines: 35
Disclaimer: Organisation given for identification purposes only