Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Effect of forgetting to release memory in C/C++ program

2 views
Skip to first unread message

Kenny McCormack

unread,
Jun 30, 2009, 4:14:39 PM6/30/09
to
In article <59c40d81-d3bb-40b3...@f38g2000pra.googlegroups.com>,
David Schwartz <dav...@webmaster.com> wrote:
>On Jun 25, 5:29�am, Kuhl <chen_zhi...@yahoo.com> wrote:
>> If I forget to release memory with free command after calloc or malloc
>> in C program, or forget to release memory with delete command after
>> new in C++ program, then what would happen to the memory space? Will
>> it be released when the program is finished? Or won't it be released
>> until the system reboots? Or what else? Thanks.
>
>These functions all allocate address space inside your process. When
>your process ceases to exist, it is logically impossible for address
>space inside that process to remain allocated, since the address space
>itself no longer exists.
>
>DS

That's the common sense, logically and obviously correct answer.

It is not, however, the CLC-pedantically-correct answer.

David Schwartz

unread,
Jun 30, 2009, 4:36:27 PM6/30/09
to
On Jun 30, 1:14 pm, gaze...@shell.xmission.com (Kenny McCormack)
wrote:

> That's the common sense, logically and obviously correct answer.
> It is not, however, the CLC-pedantically-correct answer.

Right, the CLC pedantically correct answer is: There is no way a
program can tell what happens after it terminates.

DS

Gordon Burditt

unread,
Jun 30, 2009, 5:00:40 PM6/30/09
to
>>These functions all allocate address space inside your process. When
>>your process ceases to exist, it is logically impossible for address
>>space inside that process to remain allocated, since the address space
>>itself no longer exists.
>>
>>DS
>
>That's the common sense, logically and obviously correct answer.

That's true for modern, virtual-memory multi-tasking operating
systems like UNIX, POSIX, and Windows. It's not obviously correct
for MS-DOS and some embedded systems which treat the program as
more of a subroutine rather than a process and don't separately
track memory allocation.

There are also embedded systems where the program in question never
terminates, except due to batteries running out (and sometimes they
aren't removable) or perhaps a hard reset (if such a function is
provided).

An OS which doesn't clean up after a program terminates probably
can't clean up after a program is manually aborted (if manual abort
is available), either.

Golden California Girls

unread,
Jun 30, 2009, 7:02:31 PM6/30/09
to
Kenny McCormack wrote is comp.UNIX.programmer:

> It is not, however, the CLC-pedantically-correct answer.

No one gives a ... about "CLC-pedantically-correct answer" in CUP so keep your
damn pedantics in CLC and don't cross post your pedantic flames!

James Kanze

unread,
Jul 1, 2009, 4:34:49 AM7/1/09
to
On Jun 30, 10:14 pm, gaze...@shell.xmission.com (Kenny McCormack)
wrote:
> In article
> <59c40d81-d3bb-40b3-b153-8dea09d4a...@f38g2000pra.googlegroups.com>,
> David Schwartz <dav...@webmaster.com> wrote:

> >On Jun 25, 5:29 am, Kuhl <chen_zhi...@yahoo.com> wrote:
> >> If I forget to release memory with free command after
> >> calloc or malloc in C program, or forget to release memory
> >> with delete command after new in C++ program, then what
> >> would happen to the memory space? Will it be released when
> >> the program is finished? Or won't it be released until the
> >> system reboots? Or what else? Thanks.

> >These functions all allocate address space inside your
> >process. When your process ceases to exist, it is logically
> >impossible for address space inside that process to remain
> >allocated, since the address space itself no longer exists.

> That's the common sense, logically and obviously correct answer.

> It is not, however, the CLC-pedantically-correct answer.

Note the cross-posting, however. Under Unix, the statement is
correct, but not necessarily in other environments. (And
there's nothing "obviously correct" about it, unless you're
running under a system where every process does have a separate
address space in which memory is allocated.)

--
James Kanze (GABI Software) email:james...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

cr88192

unread,
Jul 1, 2009, 12:47:30 PM7/1/09
to

"James Kanze" <james...@gmail.com> wrote in message
news:31f9e3ae-569a-47b7...@q11g2000yqi.googlegroups.com...

On Jun 30, 10:14 pm, gaze...@shell.xmission.com (Kenny McCormack)
wrote:
> In article
> <59c40d81-d3bb-40b3-b153-8dea09d4a...@f38g2000pra.googlegroups.com>,
> David Schwartz <dav...@webmaster.com> wrote:

> >On Jun 25, 5:29 am, Kuhl <chen_zhi...@yahoo.com> wrote:
> >> If I forget to release memory with free command after
> >> calloc or malloc in C program, or forget to release memory
> >> with delete command after new in C++ program, then what
> >> would happen to the memory space? Will it be released when
> >> the program is finished? Or won't it be released until the
> >> system reboots? Or what else? Thanks.

> >These functions all allocate address space inside your
> >process. When your process ceases to exist, it is logically
> >impossible for address space inside that process to remain
> >allocated, since the address space itself no longer exists.

> That's the common sense, logically and obviously correct answer.

> It is not, however, the CLC-pedantically-correct answer.

<
Note the cross-posting, however. Under Unix, the statement is
correct, but not necessarily in other environments. (And
there's nothing "obviously correct" about it, unless you're
running under a system where every process does have a separate
address space in which memory is allocated.)
>

yep, and on Windows crashing apps (or apps which fail to free them) will
gradually eat up all ones' "system resources" and eventually require a
reboot...

every next button or menu item puts the computer one step closer to needing
a reboot...

but then again, I also realize the hassle of having to go and release
everything allocated from the WIN32 API...


at least allocated memory disappears on exit...

Kenny McCormack

unread,
Jul 2, 2009, 12:34:49 PM7/2/09
to
In article <bQw2m.100$P5...@nwrddc02.gnilink.net>,

I cross-posted it intentionally. In fact, cross-posting between CUP and
CLC is about as sensible as cross-posting between, say,
alt.religion.christian.roman-catholic and alt.atheism.

Which is to say, people do it all the time - and that's how we keep
Usenet alive - by intentionally fomenting dissent between opposing
groups.

James Kanze

unread,
Jul 4, 2009, 5:58:27 AM7/4/09
to
On Jul 1, 6:47 pm, "cr88192" <cr88...@hotmail.com> wrote:
> "James Kanze" <james.ka...@gmail.com> wrote in message

That's true on all OS's. And in some cases, even a reboot
doesn't help---we've had problems with programs which ate up
disk space, for example. The question is only which resources
you have to free explicitly, and which are automatically freed
on program termination. In the case of memory, both Unix and
Windows (and most other OS's) automatically free the resource,
so there's no problem. For things like temporary files, neither
Unix nor Windows free the resource, so you have to (even if your
program crashes); I have used systems where this wasn't the case
(and there are work arounds under Unix which can usually be
used).

> every next button or menu item puts the computer one step
> closer to needing a reboot...

That was certainly true once upon a time. Today, I find that
it's the X window manager under Linux which causes that sort of
problem the most. (The one under Solaris seems to work well,
however.) Windows XP is at least an order of magnitude more
stable than the various Linux that I use (all 2.6 something).

Rainer Weikusat

unread,
Jul 5, 2009, 12:20:00 PM7/5/09
to
James Kanze <james...@gmail.com> writes:

[...]

> That was certainly true once upon a time. Today, I find that
> it's the X window manager under Linux which causes that sort of
> problem the most. (The one under Solaris seems to work well,
> however.)

There is no such thing as an 'X Windows Manager' (except maybe as
fringe project somewhere). There is an 'X-server', which is the server
implementing the 'X Window System' 'drawing protocol'. It cannot
permanently leak memory in the described way (unlike what happened the
64K user and gdi heaps): This is just a process and it is usually
terminated and restarted on logout.

> Windows XP is at least an order of magnitude more
> stable than the various Linux that I use (all 2.6 something).

Somehow, I doubt that you are simultaneously using 'all Linux 2.6
versions' and a particular version of some X-server (presumably X.org
or Xfree86) has no particular relation to a particular kernel or
version of such a kernel (IIRC, X.org supports Linux. *BSD, Hurd,
Solaris, Mac OS X and Windows).

Ralf Damaschke

unread,
Jul 5, 2009, 1:16:20 PM7/5/09
to
Rainer Weikusat wrote:

> James Kanze <james...@gmail.com> writes:
>> Windows XP is at least an order of magnitude more
>> stable than the various Linux that I use (all 2.6 something).
>
> Somehow, I doubt that you are simultaneously using 'all Linux 2.6
> versions'

Somehow I doubt that James wrote he was using all Linux 2.6 versions,
not even that he used at least two of them simultaneously.

-- Ralf

Rainer Weikusat

unread,
Jul 5, 2009, 1:35:42 PM7/5/09
to
Ralf Damaschke <rws...@gmx.de> writes:
> Rainer Weikusat wrote:
>
>> James Kanze <james...@gmail.com> writes:
>>> Windows XP is at least an order of magnitude more
>>> stable than the various Linux that I use (all 2.6 something).
>>
>> Somehow, I doubt that you are simultaneously using 'all Linux 2.6
>> versions'
>
> Somehow I doubt that James wrote he was using all Linux 2.6
> versions,

Well, he did. Other interpretations of his statement are possible, but
each can be as wrong or as right as the one I was using, and he was
making a general claim about 'Linux 2.6', apparently based on
experiences with running some version(s) of some (free)
X11-implementation(s). This doesn't make sense.

Keith Thompson

unread,
Jul 5, 2009, 3:18:53 PM7/5/09
to

The obvious interpretation is that he uses various Linux(es), all of
which happen to be 2.6 something. He didn't appear to be making any
statement about *all* 2.6 versions, just about the ones he uses.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Rainer Weikusat

unread,
Jul 5, 2009, 3:59:28 PM7/5/09
to
Keith Thompson <ks...@mib.org> writes:
> Rainer Weikusat <rwei...@mssgmbh.com> writes:
>> Ralf Damaschke <rws...@gmx.de> writes:
>>> Rainer Weikusat wrote:
>>>> James Kanze <james...@gmail.com> writes:
>>>>> Windows XP is at least an order of magnitude more
>>>>> stable than the various Linux that I use (all 2.6 something).
>>>>
>>>> Somehow, I doubt that you are simultaneously using 'all Linux 2.6
>>>> versions'
>>>
>>> Somehow I doubt that James wrote he was using all Linux 2.6
>>> versions,
>>
>> Well, he did. Other interpretations of his statement are possible, but
>> each can be as wrong or as right as the one I was using, and he was
>> making a general claim about 'Linux 2.6', apparently based on
>> experiences with running some version(s) of some (free)
>> X11-implementation(s). This doesn't make sense.
>
> The obvious interpretation is that he uses various Linux(es), all of
> which happen to be 2.6 something.

You may believe to be telephatic. I know I am not.

Keith Thompson

unread,
Jul 5, 2009, 5:08:29 PM7/5/09
to

I am neither telephatic nor telepathic. I merely read what he wrote
and interpreted it in a way that *does* make sense. James will
probably jump in and clarify this anyway.

Ian Collins

unread,
Jul 5, 2009, 6:53:24 PM7/5/09
to
Rainer Weikusat wrote:
> James Kanze <james...@gmail.com> writes:
>
>> Windows XP is at least an order of magnitude more
>> stable than the various Linux that I use (all 2.6 something).
>
> Somehow, I doubt that you are simultaneously using 'all Linux 2.6
> versions'

"the various Linux that I use" != "all"

--
Ian Collins

James Kuyper

unread,
Jul 5, 2009, 8:31:29 PM7/5/09
to
Rainer Weikusat wrote:
> James Kanze <james...@gmail.com> writes:
>
> [...]
>
>> That was certainly true once upon a time. Today, I find that
>> it's the X window manager under Linux which causes that sort of
>> problem the most. (The one under Solaris seems to work well,
>> however.)
>
> There is no such thing as an 'X Windows Manager' (except maybe as
> fringe project somewhere).

Technically you're right, but only because you've inserted an 's' that
wasn't in the original: "X window manager".

xwm, 4dwm, twm, olwm, and gnome-wm and metacity are all X window
managers that I've used (note the naming convention of wm obeyed by the
first four) - there's probably a couple of others that I don't remember
the names of. Do you consider them all to be "fringe project"s?

>> Windows XP is at least an order of magnitude more
>> stable than the various Linux that I use (all 2.6 something).
>
> Somehow, I doubt that you are simultaneously using 'all Linux 2.6
> versions'

He didn't say he was. He said that all of "the various Linux that I use"
are "2.6 something".

Barry Margolin

unread,
Jul 6, 2009, 12:22:09 AM7/6/09
to
In article <87iqi6q...@fever.mssgmbh.com>,
Rainer Weikusat <rwei...@mssgmbh.com> wrote:

Then you're not a normal human. All natural language is ambiguous, and
interpreting it is a natural part of listening and reading.

If someone said, "I just gave away a box of books, all science fiction"
would you think that he has all the science fiction books in the world
in a box? That sentence has the same structure, and this is the normal
way to express this concept.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

Richard Heathfield

unread,
Jul 6, 2009, 12:31:50 AM7/6/09
to
Rainer Weikusat said:

(Right.)

> You may believe to be telephatic. I know I am not.

To me, James Kanze's meaning of "all 2.6" is clear - it is a
contraction of "all of which are 2.6". The only other valid
interpretation I can see of what he wrote, the one you appear to
have read into it, something like "all possible distributions that
use the 2.6 kernel", is so unlikely to be true as to be not worth
considering. Consider Tux's Razor: "don't needlessly multiply
distributions".

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Forged article? See
http://www.cpax.org.uk/prg/usenet/comp.lang.c/msgauth.php
"Usenet is a strange place" - dmr 29 July 1999

Rainer Weikusat

unread,
Jul 6, 2009, 6:19:40 AM7/6/09
to
James Kuyper <james...@verizon.net> writes:
> Rainer Weikusat wrote:
>> James Kanze <james...@gmail.com> writes:
>>
>> [...]
>>
>>> That was certainly true once upon a time. Today, I find that
>>> it's the X window manager under Linux which causes that sort of
>>> problem the most. (The one under Solaris seems to work well,
>>> however.)
>>
>> There is no such thing as an 'X Windows Manager' (except maybe as
>> fringe project somewhere).
>
> Technically you're right, but only because you've inserted an 's' that
> wasn't in the original: "X window manager".

Since there are plenty of 'window managers' for X, it is more likely
that this refers to some nebulous concept like 'the Linux GUI'. X has
a spectacularly bad reputation among some people, but this is almost
completely unfounded. This is not true for each and every possible
graphics driver or combination of driver and card, this being the
(IMO) most likely source of a problem someone could consider to be an
issue of 'OS stability' (direct hardware access => possibility of
'system lockup', ie unavailable until power-cycled). Judging solely
from personal experiences, this is a problem which used to be much
more common than it is nowadays. A problem of this type is not caused
by a particular kernel or version of a particular kernel.

Rainer Weikusat

unread,
Jul 6, 2009, 6:26:28 AM7/6/09
to

There is no such thing as 'the 2.6 kernel' (although the sloppy
quantifier use certainly suggests that). A much more conceivable
assumption would be 'all subversions of Linux 2.6'
(kernel.org-sources). This is, for instance, almost true for me.
But there are fairly massive changes between the 2.6.x-releases and I
don't think that general statements above the level of certain
in-kernel interface changes, for instance, the elimination of 'task
queues', are justified.

James Kanze

unread,
Jul 6, 2009, 7:33:44 AM7/6/09
to
On Jul 5, 7:16 pm, Ralf Damaschke <rws...@gmx.de> wrote:
> Rainer Weikusat wrote:
> > James Kanze <james.ka...@gmail.com> writes:
> >> Windows XP is at least an order of magnitude more stable
> >> than the various Linux that I use (all 2.6 something).

> > Somehow, I doubt that you are simultaneously using 'all
> > Linux 2.6 versions'

> Somehow I doubt that James wrote he was using all Linux 2.6
> versions, not even that he used at least two of them
> simultaneously.

I guess I could have been more precise. Rainer's probably not a
native speaker, so missed the obvious meaning.

James Kanze

unread,
Jul 6, 2009, 7:45:48 AM7/6/09
to
On Jul 6, 12:19 pm, Rainer Weikusat <rweiku...@mssgmbh.com> wrote:

> James Kuyper <jameskuy...@verizon.net> writes:
> > Rainer Weikusat wrote:
> >> James Kanze <james.ka...@gmail.com> writes:

> >> [...]

> >>> That was certainly true once upon a time. Today, I find that
> >>> it's the X window manager under Linux which causes that sort of
> >>> problem the most. (The one under Solaris seems to work well,
> >>> however.)

> >> There is no such thing as an 'X Windows Manager' (except maybe as
> >> fringe project somewhere).

> > Technically you're right, but only because you've inserted an 's' that
> > wasn't in the original: "X window manager".

> Since there are plenty of 'window managers' for X, it is more likely
> that this refers to some nebulous concept like 'the Linux GUI'. X has
> a spectacularly bad reputation among some people, but this is almost
> completely unfounded.

Just to clarify: X does not at all have a bad reputation for me:
I seriously miss some of its functionality on Windows (where I
don't have an X server installed), and I never had any
reliability problems with X under Solaris, nor HP/UX. On the
other hand, my GUI locks up rather regularly under Linux, on
several different installations (Ubantu, SuSE and in the past,
Mandrakes). My impression is that this is due to problems in
the X server (I use Gnome on one machine, and KDE on the
others), but I've never had the occasion to really analyse the
issue---until about a month or so ago, Linux was very much a
secondary activity for me, with almost all of my real work being
done under Solaris.

> This is not true for each and every possible graphics driver
> or combination of driver and card, this being the (IMO) most
> likely source of a problem someone could consider to be an
> issue of 'OS stability' (direct hardware access => possibility
> of 'system lockup', ie unavailable until power-cycled).

It's quite possible that part (or even all) of the problem comes
from the configuration---the SuSE machines are my own, I did the
configuration, and I know it took several experiments before it
worked at all. And Solaris and Windows do have life easier:
Solaris because (at least the ones I used) runs on its own
machines, and Windows because the vendor has taken all the
necessary steps to ensure that it is correctly installed and
configured.

> Judging solely from personal experiences, this is a problem
> which used to be much more common than it is nowadays.

Definitely. In the past, I couldn't leave Linux up for more
than a couple of hours without it hanging. With more recent
versions, it's not really a frequent occurance---just often
enough to be irritating.

> A problem of this type is not caused by a particular kernel or
> version of a particular kernel.

Probably not. My subjective impression is that it is a problem
in the X server, and not the kernel itself.

James Kuyper

unread,
Jul 6, 2009, 8:35:51 AM7/6/09
to

Yes, but at least for a native speaker of English, sufficiently familiar
with the context, the single most likely assumption is "all OF WHICH ARE
subversions of 2.6".

Mark McIntyre

unread,
Jul 6, 2009, 6:30:58 PM7/6/09
to
Rainer Weikusat wrote:
> James Kanze <james...@gmail.com> writes:
>
> [...]
>
>> That was certainly true once upon a time. Today, I find that
>> it's the X window manager under Linux which causes that sort of
>> problem the most. (The one under Solaris seems to work well,
>> however.)
>
> There is no such thing as an 'X Windows Manager'

So what is fvwm, xfce etc...?

http://xwinman.org/

:-)

--
Mark McIntyre

CLC FAQ <http://c-faq.com/>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

Mark McIntyre

unread,
Jul 6, 2009, 6:32:51 PM7/6/09
to
Rainer Weikusat wrote:
> Ralf Damaschke <rws...@gmx.de> writes:
>> Rainer Weikusat wrote:
>>
>>> James Kanze <james...@gmail.com> writes:
>>>> Windows XP is at least an order of magnitude more
>>>> stable than the various Linux that I use (all 2.6 something).
>>> Somehow, I doubt that you are simultaneously using 'all Linux 2.6
>>> versions'
>> Somehow I doubt that James wrote he was using all Linux 2.6
>> versions,
>
> Well, he did.

Not in English he didn't. The above construct means (all the versions I
was using were 2.6). I appreciate English may not be your first
language, but you're wrong.

luserXtrog

unread,
Jul 7, 2009, 12:56:56 AM7/7/09
to
On Jul 6, 5:30 pm, Mark McIntyre <markmcint...@TROUSERSspamcop.net>
wrote:
> Rainer Weikusat wrote:

> > James Kanze <james.ka...@gmail.com> writes:
>
> > [...]
>
> >> That was certainly true once upon a time.  Today, I find that
> >> it's the X window manager under Linux which causes that sort of
> >> problem the most.  (The one under Solaris seems to work well,
> >> however.)
>
> > There is no such thing as an 'X Windows Manager'
>
> So what is fvwm, xfce etc...?
>
> http://xwinman.org/
>
>         :-)

There is some issue of names, is there not?
The O'Reilly book take great pains to emphasize that the product
name is The X Window System. As in: don't abbreviate the System!

--
lxt

James Kanze

unread,
Jul 7, 2009, 7:52:16 AM7/7/09
to

> > > [...]

> >http://xwinman.org/

> > :-)

Except that the window managers aren't part of the X Window
System per se, but are external to it---as far as the X Window
System is concerned, they're clients as well (albeit special
clients).

FWIW: I was a bit careless in my nomenclature---since I have the
problems under both Gnome and KDE, I presume that the problem is
in the X server, and not the window manager.

Keith H Duggar

unread,
Jul 7, 2009, 6:03:46 PM7/7/09
to

I'm curious, have you tried mwm (Motif Window Manager)? I've had
very stable experience with mwm. Though my work is very "raw" ie
just a bunch of xterms, a browser, mutt, gnuplot and very rarely
some other GUI or two. I regularly run for months without crash.

KHD

James Kanze

unread,
Jul 8, 2009, 8:20:59 AM7/8/09
to

Except maybe for looking at it, no. (When I first installed
Linux, some years ago, I gave each of the Window Managers a
quick glance.) I've not actually started using Linux
intensively until recently, so I haven't had the occasion to
explore all of its possibilities.

Nobody

unread,
Jul 8, 2009, 12:25:41 PM7/8/09
to
On Tue, 07 Jul 2009 15:03:46 -0700, Keith H Duggar wrote:

>> FWIW: I was a bit careless in my nomenclature---since I have the
>> problems under both Gnome and KDE, I presume that the problem is
>> in the X server, and not the window manager.
>
> I'm curious, have you tried mwm (Motif Window Manager)? I've had
> very stable experience with mwm. Though my work is very "raw" ie
> just a bunch of xterms, a browser, mutt, gnuplot and very rarely
> some other GUI or two. I regularly run for months without crash.

X crashes are usually down to the X server. The main problem is that
modern video hardware is insanely complex, documentation is often only
available under NDA, and vendor-supplied binary drivers often leave a lot
to be desired.

If you want reliability, an older video card is often better than the
latest model, as there's more likely to be an open-source driver, and more
of the bugs will have been fixed.

If you want hardware 3D acceleration, you're generally stuck with using a
vendor-supplied binary driver.

0 new messages