473,395 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Will the allocated memory be released after process exits?

Hello experts,

When I allocate memory use malloc() and forget to call a corresponding
free(), does this allocated memory lose forever after program exits
(Can i regard it same as process exits? )?

Or will the allocated memory be released after program exits?

Sincerely,

lovecreatesbeauty

Nov 15 '05 #1
2 2043
lovecreatesbeauty wrote:

When I allocate memory use malloc() and forget to call a corresponding
free(), does this allocated memory lose forever after program exits
(Can i regard it same as process exits? )?
The standard does not specify this.*
Or will the allocated memory be released after program exits?


On modern desktop operating systems, yes. On more specialised
operating systems, perhaps not.

You should structure your code so that you can easily deallocate
any and all dynamic objects. However, many programs avoid actually
doing the deallocation on program exit because, one some systems,
it can needlessly cause the system to thrash.

However, the more complicated your program, the more sense it makes
to deallocate memory. If system resources are tied to given memory
allocations, then the deallocation routines in your code can (and
should) untie/close those system links as the same time.

So, the choice is yours.

* Certainly not in any way that a strictly conforming program could
ever tell.

--
Peter

Nov 15 '05 #2

lovecreatesbeauty wrote:
Hello experts,

When I allocate memory use malloc() and forget to call a corresponding
free(), does this allocated memory lose forever after program exits
(Can i regard it same as process exits? )?

Or will the allocated memory be released after program exits?


If you include your code in a try/catch block it will be dealocated by
garbage collector. But this is implemented only in a few compilers as
a add-on, like lcc.
Please ermember that this has nothing to do with the C standard.
example
try
{
//code here
}

catch(/*Exception e*/)
{
//do something with the exception or throw it again
}

If you know java this will be very easy.

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Rabbit63 | last post by:
Hi: I want to show a set of records in the database table on the clicnt browser. I have two ways to do this (writen in JScript): 1.The first way is: <% var sql = "select firstname from...
3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
7
by: Curley Q. | last post by:
for(;;) { c = a * b; c %= 100000; printf("%9d", c); d = int2str(c); left = midstr(d, 0, 3); right = midstr(d, strlen(d)-3, 3); free(d); a = atoi(left);
29
by: keredil | last post by:
Hi, Will the memory allocated by malloc get released when program exits? I guess it will since when the program exits, the OS will free all the memory (global, stack, heap) used by this...
11
by: Ted Miller | last post by:
Hi folks. So I'm in the middle of porting a large (previously COM-based) imaging library to .Net. The clients of this library are VB programmers within the company I work for. Their code will be...
9
by: benoit808 | last post by:
I don't have a lot of experience with C++ so I apologize if this is a stupid question. I use Paul Nettle's memory manager (mmgr.cpp) which reports a memory leak but I don't think there's one. Here...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.