releasing memory doubt

This is a discussion on releasing memory doubt within the C++ Programming forums, part of the General Programming Boards category; what will be the real memory releasing behaviour of following code snippet. Will all memory release properly? - Code: Class ...

  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    4

    releasing memory doubt

    what will be the real memory releasing behaviour of following code snippet. Will all memory release properly? -

    Code:
    Class A
    {
    };
    
    Class B : public A
    {
    };
    
    main()
    {
    
    A *ptr = new B;
    A *ptr1 = new B[10];
    
    delete ptr;
    delete [] ptr1;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,993
    Both the delete and the delete[] result in undefined behaviour since A does not have a virtual destructor, yet you attempt to destroy an object (or array thereof) of B through a pointer to A.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,828
    main should return int. Omitting return types for functions is ill-formed in C++.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Questions about releasing memory...
    By adarpodracir in forum C Programming
    Replies: 10
    Last Post: 04-07-2012, 04:10 PM
  2. Replies: 4
    Last Post: 11-10-2009, 05:47 PM
  3. Doubt about freeing memory
    By guillermoh in forum C Programming
    Replies: 9
    Last Post: 02-04-2008, 04:26 PM
  4. threads not releasing memory?
    By Spark in forum C Programming
    Replies: 3
    Last Post: 06-08-2002, 02:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21