Leak or no leak ??

Discussion in 'C Programming' started by Richard Heathfield, Jul 10, 2006.

  1. 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)
     
    Richard Heathfield, Jul 10, 2006
    #1
    1. Advertising

  2. Richard Heathfield

    Olivier Guest

    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
     
    Olivier, Jul 10, 2006
    #2
    1. Advertising

  3. Richard Heathfield

    Olivier Guest

    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.
     
    Olivier, Jul 10, 2006
    #3
  4. 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
     
    Nick Keighley, Jul 10, 2006
    #4
  5. 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)
     
    Richard Heathfield, Jul 10, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Y3liZXJzdHJpa2U=?=

    datagrid memory leak?

    =?Utf-8?B?Y3liZXJzdHJpa2U=?=, Jan 3, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    466
    =?Utf-8?B?Y3liZXJzdHJpa2U=?=
    Jan 3, 2005
  2. =?Utf-8?B?SWxhbiBPc3Npbg==?=

    .Net Seems to be Causing DLL Memory Leak?

    =?Utf-8?B?SWxhbiBPc3Npbg==?=, Feb 28, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    544
    Amit Bahree
    Mar 9, 2005
  3. chintan jajal via .NET 247

    Delegates Memory Leak!!!

    chintan jajal via .NET 247, May 26, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    2,196
    chintan jajal via .NET 247
    May 26, 2005
  4. Andromodon

    Memory leak in Xilinx? Code error?

    Andromodon, Mar 30, 2005, in forum: VHDL
    Replies:
    2
    Views:
    1,464
    Andromodon
    Apr 1, 2005
  5. Dan

    Memory leak?

    Dan, Oct 30, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    409
    Cowboy \(Gregory A. Beamer\)
    Oct 30, 2003
Loading...

Share This Page