Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. [solved] memory deallocation and the delete keyword
Forum Updated to NodeBB v4.3 + New Features

[solved] memory deallocation and the delete keyword

Scheduled Pinned Locked Moved C++ Gurus
25 Posts 7 Posters 23.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mlong
    wrote on 11 Aug 2011, 19:42 last edited by
    #21

    Indeed.

    I think the point that Lukas was making here:

    bq. No, you never ever call delete on the object which is currently destructed.

    Was that you'd never have the situation of:

    @
    a::~a() {
    // BAD CODE:
    delete this; // You would never delete an item from within its own destructor.
    }
    @

    (At least that's what I took it to mean.)

    Software Engineer
    My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      loladiro
      wrote on 11 Aug 2011, 19:43 last edited by
      #22

      [quote author="Giorgos Tsiapaliwkas" date="1313091362"]
      the follow is true or false?

      @delete pointer;
      pointer=0;

      if (pointer) {
      ....}@

      [/quote]
      Everything inside the if will not be executed (0 is false, everything else is true - just like with ints)

      1 Reply Last reply
      0
      • T Offline
        T Offline
        terietor
        wrote on 11 Aug 2011, 20:51 last edited by
        #23

        thank you for your answers.

        i will mark this thread as solved

        terietor.gr

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rokemoon
          wrote on 12 Aug 2011, 05:43 last edited by
          #24

          [quote author="mlong" date="1313090165"]
          Caveat: Smart pointers are great tools to help manage the lifespan of objects, but they still require a base knowledge of what pointers are all about at their lowest level. It's important to make sure that you have a grasp of the fundamentals before using the higher-level counterparts, though. That's just IMHO, though.
          [/quote]
          I completely agree with you mlong. I was a bit hasty with this.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on 12 Aug 2011, 13:06 last edited by
            #25

            [quote author="Giorgos Tsiapaliwkas" date="1313091362"]
            [quote author="Lukas Geyer" date="1313089715"]
            No, you never ever call delete on the object which is currently destructed.[/quote]

            if i have this ...[/quote]

            You are of course allowed to create and delete objects within a destructor - but you should never delete yourself (delete this). See mlong's post.

            1 Reply Last reply
            0

            21/25

            11 Aug 2011, 19:42

            • Login

            • Login or register to search.
            21 out of 25
            • First post
              21/25
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved