free RAM memory

This is a discussion on free RAM memory within the C++ Programming forums, part of the General Programming Boards category; how can we delete char, int, FILETIME?? I delete char from ram like this: Code: char* recent = (char*) malloc(256); ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    44

    free RAM memory

    how can we delete char, int, FILETIME?? I delete char from ram like this:

    Code:
    char* recent = (char*) malloc(256);
    ........
    free(recent);
    but others??..

    and I have one more questions.. exampla: we have deneme char from asd function(not in main function).. when deneme char cleaned from RAM memory.. while closed function or while closed exe??? sory my english

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    You only need to free memory allocated on the heap with malloc()/calloc()/alloc() (in C) or new() (in C++). If allocated with malloc()/calloc()/alloc(), then you use free() to free the memory; if allocated with new(), then use delete to free the memory).

    Other variables are created on the stack and will be "freed" when the function in which they're declared goes out of scope.

    Also, do not cast the result of malloc; it is unnecessary and potentially hides important errors. If you need to cast it because you are receiving errors, it is because you are compiling a C program using C++. If you are really using C++, you should be allocating memory with new instead.
    Last edited by rags_to_riches; 05-11-2008 at 07:04 AM. Reason: Grammar

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tools for finding memory leaks
    By stanlvw in forum C++ Programming
    Replies: 4
    Last Post: 04-03-2009, 11:41 AM
  2. Problems with shared memory shmdt() shmctl()
    By Jcarroll in forum C Programming
    Replies: 1
    Last Post: 03-17-2009, 10:48 PM
  3. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 12:57 AM
  4. Is this code memory leak free? ---> POSIX Threads
    By avalanche333 in forum C++ Programming
    Replies: 9
    Last Post: 04-13-2007, 03:19 PM
  5. Help needed with backtracking
    By sjalesho in forum C Programming
    Replies: 1
    Last Post: 11-09-2003, 05:28 PM

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