Results 1 to 5 of 5

Thread: Deallocating dynamically allocated heap

  1. #1
    Expert Member
    Join Date
    Oct 2006
    Answers
    209

    Deallocating dynamically allocated heap

    When i am dynamically allocating memory (heap) in a program, and in this case if i am not making an explicit deallocation call or free() call then when will this dynamicaaly allocated heap will get deallocated.Is it at the end of program or is it at the end of c session or is it when i shut down my system.

    NOTE : [This question was asked by Leomachy]


  2. #2
    Junior Member
    Join Date
    Jul 2007
    Answers
    18

    Re: Deallocating dynamically allocated heap

    i think you get solution by follow the following steps:

    -->write some C, c++ any code which will alocate some memory.
    -->note down the address where you are allocating the memory.
    -->Now meanwhile write and open another C program, which will display the
    content of memory that you are allocating previously.
    -->for the first program ,,,end the session and check in the second C program.
    -->


  3. #3
    Junior Member
    Join Date
    Jul 2007
    Answers
    18

    Re: Deallocating dynamically allocated heap

    i think you get solution by follow the following steps:

    -->write some C, c++ any code which will alocate some memory.
    -->note down the address where you are allocating the memory.
    -->Now meanwhile write and open another C program, which will display the
    content of memory that you are allocating previously.
    -->for the first program ,,,end the session and check in the second C
    program.
    --> same way quit from the application and check in the second C program
    memory content.
    ....................
    -->


  4. #4
    Junior Member
    Join Date
    Jul 2007
    Answers
    2

    Re: Deallocating dynamically allocated heap

    Quote Originally Posted by JobHelper View Post
    When i am dynamically allocating memory (heap) in a program, and in this case if i am not making an explicit deallocation call or free() call then when will this dynamicaaly allocated heap will get deallocated.Is it at the end of program or is it at the end of c session or is it when i shut down my system.

    NOTE : [This question was asked by Leomachy]

    When a malloc() is called some physical memory is mapped on to your process address space. When your process will ends up this memory will return to the system.


  5. #5
    Junior Member
    Join Date
    Jun 2007
    Answers
    3

    Re: Deallocating dynamically allocated heap

    The allocated memory will last till you process ends. But this is not a good practice, u shuld deallocate the memory what u allocate else it can cause memory leak and your system will crash


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact