473,386 Members | 1,804 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,386 software developers and data experts.

Leak or no leak ??

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
Jul 10 '06 #1
4 1213
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)
Jul 10 '06 #2
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.
Jul 10 '06 #3
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

Jul 10 '06 #4
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)
Jul 10 '06 #5

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

Similar topics

10
by: Debian User | last post by:
Hi, I'm trying to discover a memory leak on a program of mine. I've taken several approaches, but the leak still resists to appear. First of all, I've tried to use the garbage collector to...
2
by: Elbert Lev | last post by:
#When I'm running this script on my windows NT4.0 box, #every time dialog box is reopened there is memory growth 384K. #Bellow is the text I sent to Stephen Ferg (author of easygui) # I have...
3
by: Jeremy Lemaire | last post by:
Hello, I am working on cross platform code that is displaying a huge memory leak when compiled on 11.00 HPUX using the aCC -AA flag. It is not leaking on NT, LINUX, Solaris, or HPUX without the...
4
by: Mark D. Anderson | last post by:
About a month ago Richard Cornford did an interesting analysis of a memory leak in jscript (internet explorer) when there are "circular" references between DOM objects and (real) jscript objects:...
8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
17
by: José Joye | last post by:
Hi, I have implemented a Service that is responsible for getting messages from a MS MQ located on a remote machine. I'm getting memory leak from time to time (???). In some situation, it is...
23
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
0
by: fergaloc | last post by:
Hi there. Our .net framework 1.1 application is a complex media player that plays back video, flash, web, TV and pictures full screen. It runs on Windows XP SP2. It has 12 DLLs and runs to about...
22
by: Peter | last post by:
I am using VS2008. I have a Windows Service application which creates Crystal Reports. This is a multi theaded application which can run several reports at one time. My problem - there is a...
18
by: Daniel Orner | last post by:
Hi all, I've been trying to pin down a memory leak in IE6 for several WEEKS now. I've done my share of googling etc., and know all about common leaks like circular references and closures, but...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.