Leak or no leak ??

R

Richard Heathfield

Olivier said:

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>
 
O

Olivier

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
 
O

Olivier

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.
 
N

Nick Keighley

Olivier said:
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).
 
R

Richard Heathfield

Nick Keighley said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top