Thread: When should I delete Objects ?

  1. #1

    Question When should I delete Objects ?

    Hello all,

    I have the following code which prints out all the videos I have stored in a linked list :

    void viewList(list<vid> &li)

    cout<< "\t\t\t\t *List of films*\n";

    cout<< "\t\t\t*****************************\n"<<endl;
    for(it=li.begin(); it!=li.end(); ++it)
    vid t;
    t = *it;
    cout << "\t\t\t" << t.getTitle() << endl;
    cout<< "\t\t\t*****************************\n"<<endl;

    What I want to know is if this code is BAD ? Do I have to delete the vid Object t which I use to enable me to print out the title each time.

    If so do I do this in a destructor and how ??

    Thank you


  2. #2
    Super Moderator
    Join Date
    Sep 2001
    You usually delete objects as soon as they're no longer needed if you're using a large program, but if it is a matter of indifference, just at the end. If deleting objects becamse a major task for you, you may want to try using Java. It's very similar, but has automatic object deletion. As soon as an object is no longer referenced, the JVM deletes it.

  3. #3
    I also wish to know how this is done though ?

    How does he delete the vid Object, and does he actually need to delete it ?

  4. #4
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    non-static non-global objects are deleted upon the end of their scope, but anything else requires manual deletion.
    hasafraggin shizigishin oppashigger...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cannot delete objects
    By theJ89 in forum C++ Programming
    Replies: 7
    Last Post: 03-30-2006, 10:25 PM
  2. delete and delete []
    By Lionel in forum C++ Programming
    Replies: 8
    Last Post: 05-19-2005, 01:52 PM
  3. Problem need help
    By Srpurdy in forum C++ Programming
    Replies: 1
    Last Post: 07-24-2002, 12:45 PM
  4. memory management...
    By master5001 in forum Game Programming
    Replies: 24
    Last Post: 01-07-2002, 05:50 PM
  5. how to delete objects
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 08-31-2001, 02:06 AM