Path: 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: 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 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 | +-=-=-=-=-=-=-=-=-=-=-=-=-=-=+=-=-=-=-=-=+=-=-=-=-=-=-=-=-=-=-=-=-=-+