Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Leak or no leak ??

Reply
Thread Tools

Leak or no leak ??

 
 
Richard Heathfield
Guest
Posts: n/a
 
      07-10-2006
Olivier said:

<snip>

> When quitting, a good
> amount of memory is still allocated:


As a matter of good programming practice, a professional programmer prefers
specifically to release any memory that he or she has allocated.
Nevertheless...

> is
> it restored when the program terminates?


....a decent modern protected-mode operating system is extremely unlikely to
allow a program to consume Megabytes of memory and then die with the memory
still allocated - it's going to want that memory back. So yes, the OS will
in all likelihood grab the memory when the program quits. But the C
Standard does not mandate this, and there may well be occasional systems
that don't do it, but you are unlikely to run into them.

> I mean, does the OS take care of that
> or should I carefully deallocate everything?


Both!

<snip>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
 
 
 
Olivier
Guest
Posts: n/a
 
      07-10-2006
Dear all,

I have a C programm
Lots of gtk widgets and I'm afraid global
variables When quitting, a good
amount of memory is still allocated: is
it restored when the program terminates?
I mean, does the OS take care of that
or should I carefully deallocate everything?

During runtime the amount of this "base"
allocated memory doesn't increase. I can check
that most of the "runtime" memory is properly
deallocated: the program does that (as
it does it between every change of main state).
When I use "free" before and after call
(it shows the amount of memory used), there
is an increase of about 2.5M which seems at lot
to me (who started programming 20 years back
with flexible disks :-p)). The cache on the other
side does almost not increase.

In case of relevance: this is linux (debian sarge).
Best !
Amities,
Olivier
 
Reply With Quote
 
 
 
 
Olivier
Guest
Posts: n/a
 
      07-10-2006
Richard Heathfield a écrit :
[...]>
...a decent modern protected-mode operating system is extremely
unlikely to
> allow a program to consume Megabytes of memory and then die with the memory
> still allocated - it's going to want that memory back. So yes, the OS will
> in all likelihood grab the memory when the program quits. But the C
> Standard does not mandate this, and there may well be occasional systems
> that don't do it, but you are unlikely to run into them.


Ok, thanks !
This program is a game, though a huge one , but understanding what
has or hasn't been allocated / deallocated will be a good exercise
in C / GTK. But no hurry.
A.O.
 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      07-10-2006
Olivier wrote:
> Dear all,


> I have a C programm
> Lots of gtk widgets and I'm afraid global
> variables


loose the global variables. Really.

(for the pedantic, yes my programs have global variables, mostly mode
switches such as "quiet/verbose". But there a few of them).



--
Nick Keighley

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      07-10-2006
Nick Keighley said:

> Olivier wrote:
>> Dear all,

>
>> I have a C programm
>> Lots of gtk widgets and I'm afraid global
>> variables

>
> loose the global variables. Really.


Please don't. I'd much prefer it if you kept them under control, or humanely
put them to sleep. There are already way too many of them out there in the
wild. Personally, I blame the Government.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Firefox memory leak ttfg Firefox 4 03-18-2005 06:32 PM
.Net Seems to be Causing DLL Memory Leak? =?Utf-8?B?SWxhbiBPc3Npbg==?= ASP .Net 1 03-09-2005 05:38 PM
Firefox Memory Leak? Scott Moseman Firefox 2 02-09-2005 03:52 PM
Wireless Zero Configuration Memory Leak?? =?Utf-8?B?Umlja3NjaHVsdHox?= Wireless Networking 3 01-19-2005 11:26 PM
datagrid memory leak? =?Utf-8?B?Y3liZXJzdHJpa2U=?= ASP .Net 0 01-03-2005 10:17 PM



Advertisments