Pointer leaks?

This is a discussion on Pointer leaks? within the C++ Programming forums, part of the General Programming Boards category; I know alot of languages have this common problem, where you allocate a bit of memory, but it needs to ...

  1. #1
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379

    Question Pointer leaks?

    I know alot of languages have this common problem, where you allocate a bit of memory, but it needs to be manualy destroyed. I know that all basicaly allocated memory (int,char,ect) is all deleted at the end of the function or program depending on how you used it.

    But I was recently told that it's a good idea to clean up pointers before your program exits, can anyone shead some light on this? Bit confused as it stands
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Quote Originally Posted by Blackroot View Post
    I know alot of languages have this common problem,
    Problem?

    I know that all basicaly allocated memory (int,char,ect)
    There's some confusion here. The type has nothing to do with how the thing is allocated. The location of the declaration is all that matters. Variables inside functions are in automatic storage and automatically cleaned up when the containing block is left. Variables outside functions (and outside classes) are in static storage and are cleaned up when the program ends. Stuff allocated with new is in dynamic storage and must be explicitly deallocated.

    But I was recently told that it's a good idea to clean up pointers before your program exits, can anyone shead some light on this? Bit confused as it stands
    It's a good idea to clean up pointers when you no longer need what they point to. Probably it's the last chance you get. How what you were told relates to this, I have no idea.
    All the buzzt!
    CornedBee

    "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

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    Quote Originally Posted by CornedBee View Post
    Problem?
    Offtopic: I asked the same question (Problem?) recently and got the answer, that modern garbage collection is a lot faster then manual free storage management. I that true?

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    No. It's faster than naive manual free storage management, though. I wouldn't say it's a lot faster.
    All the buzzt!
    CornedBee

    "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

  5. #5
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630
    Whats 'modern garbage collection' and 'manual free storage' ?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,893
    Whats 'modern garbage collection' and 'manual free storage' ?
    Garbage collection.

    CornedBee meant "manual (free storage management)", not "(manual free storage) management".
    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

  7. #7
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Thanks for the clarification, definantly not as bothersome to clean as some languages, luckily.
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  2. What is a virtual function pointer?
    By ting in forum C++ Programming
    Replies: 4
    Last Post: 03-05-2008, 01:36 AM
  3. Parameter passing with pointer to pointer
    By notsure in forum C++ Programming
    Replies: 15
    Last Post: 08-12-2006, 07:12 AM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM

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