Thread: memory fault/leak

  1. #1
    Registered User
    Join Date
    Sep 2009

    Question memory fault/leak

    Can this code have a memory fault/leak?

    class A {
    ~A() {}
    vector<B> b;
    class B {
    ~B() {}
    map<C, string> c_map;
    Class C {
    main() {
    C c1,c2,c3,c4;
    B b1,b2;
    b1.c_map(c1) = "c1";
    b1.c_map(c2) = "c2";
    b2.c_map(c3) = "c3";
    b2.c_map(c4) = "c4";
    A *a = new A();
    delete a;

  2. #2
    The larch
    Join Date
    May 2006
    It doesn't have a memory leak.* Are you asking because of the empty destructor? Destructors of members are still called (automatically after user-defined destructor completes) - you can't change this feature of destructors.

    *Because of the use of a dumb pointer and not catching exceptions, this code can (theoretically) leak, should either of the push_back's trigger an exception to be thrown.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    However, it does have at least two syntax errors. Also, your map is either not a standard map, which means there could be memory leaks in there, or you have four more syntax errors.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    Sep 2009
    Thank You, anon & Corned Bee, thanks for the reply

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. available memory from task manager
    By George2 in forum Tech Board
    Replies: 10
    Last Post: 01-18-2008, 02:32 AM
  2. Replies: 4
    Last Post: 01-13-2008, 02:14 AM
  3. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 01:57 AM
  4. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  5. Shared Memory - shmget questions
    By hendler in forum C Programming
    Replies: 1
    Last Post: 11-29-2005, 02:15 AM