delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/01/13:01:38

From: sl AT psycode DOT com DOT NOSPAM (Gili)
Newsgroups: comp.os.msdos.djgpp
Subject: Classes, Cloning and memory loss
Date: 1 Jun 1998 12:07:31 GMT
Organization: All USENET -- http://www.Supernews.com
Lines: 24
Message-ID: <bWLoegW7sFse-pn2-Vb9d9LjxJy4K@portX45.lanzen.net>
Reply-To: sl AT psycode DOT com DOT NOSPAM
NNTP-Posting-Host: 205.205.70.64
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hello,

	I have the following class:

class SLList
{
public:
  SLList *clone();
  operator=();
private:
  int *value;
}

	clone() creates another instance of the class, containing the same 
value for 'value', but not the same pointer (it allocates new memory.)
Operator=() deletes the old instance and copies the memory location of
the new instance (shares the memory.) My question is... If I say 
'temp=someSLList.clone()'... someSLList.clone() never gets delete()d, 
temp does.. But since temp and someSLList shared the same value, is 
delete()ing temp enough? Will someSLList be left floating somewhere in
memory if I only delete() its variables from another instance? Thank 
you,

Gili

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019