473,799 Members | 3,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Garbage collection problems

As many people know, I think that garbage collection is a good
solution for many memory allocation problems.

I am aware however, that nothing is "the silver bullet", not
even the GC.

A recent article in slashdot
http://developers.slashdot.org/artic.../11/17/0552247
proves that.

A C# application was leaking memory, and the application would
become slower and slower because the memory was getting full and the
system was swapping like mad until it just failed.

Why?

Because a list that should be destroyed wasn't being destroyed.
This is similar to another bug that Sun discovered in their
Java implementation. The list wasn't being destroyed because
SOMEWHERE there was a reference to that list, and the GC could
not destroy it.

It is interesting to note that this bug is as difficult to trace as
a missing free or similar bugs. It required a specialized tool
to find it (yes, there are specialized tools to solve GC memory
allocation problems as there are specialized tools to solve
non-gc memory allocation problems)

The lesson to be learned is that you have to be careful (when using the
GC) to
1) Set all pointers to unused memory to NULL.
2) Do NOT store pointers to GC memory in permanent structures if you
want that data to eventually be collected.

The above bug was that the list registered itself in a global
data structure and wasn't getting destroyed.

If the GC wouldn't have been there, the programmer would have freed
the memory, what would have closed the memory leak but left
a dangling pointer in the global data structure!

Not a better alternative.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Nov 18 '07
84 3555
(This is now about "stack unwinding", as in throw in C++ or longjmp
in C, rather than GC.)

In article <9c************ *************** *******@t47g200 0hsc.googlegrou ps.com>
Paul Hsieh <we******@gmail .comwrote:
>Functions calls are to push as return is to pop. It might not be
*called* a stack, but it *IS* a stack ...
Indeed, function call and return -- and exception-handling or nested
setjmp() operations -- function as a kind of stack. There are some
significant differences between C and C++ here though, including
the fact that in C, the onus of "using longjmp only in a stack-like
manner" is placed entirely on the C programmer. A C++ programmer
using "throw" cannot accidentally pass an invalid goto-label-buffer
(C's "jmp_buf").
>And as long as we are talking about reality, we should note that most
C implementations use a literal common stack for both return/link
addresses and autos.
Most, but not all. Significantly, many modern compilers optimize
"leaf" procedures to avoid separate stack frames, and some (probably
not as many) will use both "fake" and "real" frame pointers (as on
MIPS CPUs, where a frame pointer is generally used only if the size
of the stack frame varies, e.g., due to C99 VLAs).
>... To run an exception the system, one way or another needs to implement
"pop (return) until catch found" at runtime without actually executing
the returns, which means that a uniform "pseudo-return" has to exist
outside of implicit execution.
One should, however, note that "uniform" can apply only after a
sort of union operation. The stack-unwind code might, for instance,
read something like this (here target_frame is assumed to be given
directly via longjmp; for exceptions it has to be calculated):

target_frame = jmpbuf_info[0]; /* or whatever index */
while (curframe != target_frame) {
switch (calculate_fram e_type(curframe )) {
case FRAME_IN_LEAF_F UNCTION: /* can only happen once */
prevframe = jmpbuf_info[1]; /* or whatever */
break;
case FRAME_WITH_REAL _FRAME_POINTER:
prevframe = curframe->prev;
break;
case FRAME_WITH_VIRT UAL_FRAME_POINT ER:
prevframe = curframe + compute_offset( curframe);
break;
default:
__panic("longjm p");
/* NOTREACHED */
}
}
>Using longjmp is insufficient because you can set catch #1, then call
into something, then set catch #2, then return enough times to make
catch #2 no longer in the call stack scope, thus re-enabling catch
#1.
Indeed. However, longjmp() is *also* insufficient simply because
it just does not work properly: it may trash any non-"volatile"-qualified
variables local to the target of the longjmp()[*]. But if the compiler
is clever enough (i.e., so that setjmp/longjmp do not destroy local
variable values; and note that longjmp() is provided by the
compiler-writer, who can decide whether his compiler is sufficiently
clever), the same kinds of innards used in longjmp() *can* be used
to implement exceptions, as long as "catch" records something about
the call stack and "throw" can use that to decide whether catch-#2
is "active", for instance.

In the case of several real GCC implementations , throw really does
work a lot like the above, with the target frame being computed
somewhat dynamically and calculate_type_ frame() and compute_offset( )
being rather complicated operations that match the "instructio n
pointer" (PC or IP register, typically) of the supplied frame[%]
against large "exception info" tables, all so that ordinary function
call and return need not manipulate the current catch stack. (In
other words, the compiler throws code-space at the problem, to
avoid a time penalty.)

[* If I had been writing the C standard, I think I would have
forced compiler-writers to handle setjmp/longjmp non-local "goto"
operations "correctly" . In other words, I would have put the
burden on compiler-writers instead of C programmers, so that C
programmers would not have to mark variables "volatile" to get
predictable behavior when using longjmp.]

[% Even worse, the return-PC is often not in that frame, but rather
one frame away and/or "adjusted" somehow. Some CPUs save the PC
of the "call" instruction, some save the PC of the "next" instruction.
Some even have funny special-case frames in which multiple PCs are
saved. If longjmp and/or throw are to work across "exception"
frames, including Unix-like signal handlers, these also must be
handled.]
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 22 '07 #81
Paul Hsieh wrote:
On Nov 20, 4:31 am, Chris Dollin <chris.dol...@h p.comwrote:
>It might not be zero, unless there's a way to tell the compiler to
compile compilation units assuming that they'll be used in an EH-free
program: it's possible that code that might execute in an EH
environment might suffer optimisation penalties. On the other hand,
I don't see that they'd be much different from any penalties already
paid for set/longjmp.

The set/longjmp storage is handled by the programmer. With EH, it has
to dynamically be stored somewhere -- presumably in the stack itself
(this seems to be the only solution that would make sense in multi-
threaded environments.)
I meant optimisation opportunities for the non-exceptional code, not mere
storage for the jmp_buf equivalent.

When you have exceptions, there are (possibly) more places at which the
behaviour of the code is constrained, and hence more places where an
optimisation cannot be applied.

Working out a specification [and implementation] for exceptions-in-C
which is effective /and/ doesn't mess C up for the microoptimisati onophiles
is, I believe, non-trivial, and (bringing me back to my earlier position
statement) significantly harder than namespaces would be. IMAO.

--
Chris "glad I don't have to do it" Dollin

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

Nov 22 '07 #82
cr88192 wrote:
as for "special flexibility", at least in scheme implementations , where this
kind of thing is often done, this adds in features like easy support for
continuations and lexical scoping (neither of which are traditionally
present in C).
Nitpick: C /is/ lexically scoped. What C doesn't have is /full/ lexical
scoping, across nested functions, because it doesn't have nested functions
at all.

[One of the benefits of garbage collection being built-in to a language
is that it can handle the really full bits of lexical scoping where a
function that refers to a local variable from an enclosing function
/can be exported/ as a fully-fledged function object. Doing that with
neither GC nor storage leaks is ... harder.]

--
Chris "seeking a life of ease and comfort" Dollin

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

Nov 22 '07 #83

"Tor Rustad" <to********@hot mail.comwrote in message
news:-5************** *******@telenor .com...
cr88192 wrote:
>"Tor Rustad" <to********@hot mail.comwrote in message
news:hJ******* **************@ telenor.com...
>>cr88192 wrote:
"Tor Rustad" <to********@hot mail.comwrote in message
[...]

IMO, the main domain of C is system and embedded development. Even if
extending this domain by including communication, security development
and DB engine development, a GC seems neither important, or of much
interest.
>
errm, are you trying to claim that all of us good old desktop-pc
developers are all off using stuff like Java and C# or something?...
No, I say that C1X should focus on the main domain of C, and try to keep
the language small and simple. The C99 variable-length arrays was a step
too far. Adding GC to Standard C, would IMO be a major mistake.

I will agree to a point here:
those kind of arrays, IMO, do not belong within the main language.

but, GC is a runtime feature, and it is very sensible that it be left out
for embedded targets.

Yes, perhaps the fragmentation of memory issue when using GC has been
solved these days, but not long ago, it wasn't AFAIK. Besides, my MISRA C
copy, prohibits non-deterministic memory allocations anyway.
ok.

>
>I was not arguing for standardized GC though, only that GC, itself, has
value. where and for who it has value, are the people who use it.

Well, we do discuss in the context of Standard C here, so when a
non-existing features is the subject, particularly when OP is J.N. (!) --
I assume he want it added.
ok.

well, I have not been reading his posts long enough to know what he thinks.

>>>must of us are in a land where we still want things like GC, but don't
feel like selling our souls to some proprietary VM framework to get it.
Nobody is stopping you from using the Boehm GC.

what do you think I was arguing through most of the thread?...

this is what I was arguing, that using Boehm is a very valid and sensible
option (however, certain other people were opposing that GC has use in C
land, ever...).

I have never used GC myself, but has no strong feelings against some
high-level applications using such libraries, but I wouldn't like to see a
GC during audit, in security and/or safety related software.
yes, it is not the best idea, everywhere.

I don't expect it to be a magic bullet everywhere or anything. so, for some
subsystems I use it, and for others, I don't.

for example, I have certain libraries in my projects which, very simply,
don't use GC...
a lot depends on the specific design philosophy of that particular
subsystem.
some subsystems are very single-tasked, and generally follow a "closed"
design, and generally do not use any GC or other features (and are very
strict and do not allow any dependency on external code, or, for one of my
libs, severely limits allowed internal access as well).

other libs are a lot more open, and depend on many other subsystems, and
tend to rely fairly heavily on GC.

--
Tor <bw****@wvtqvm. vw | tr i-za-h a-z>

Nov 22 '07 #84
On 19 Nov 2007 08:54:05 GMT, ri*****@cogsci. ed.ac.uk (Richard Tobin)
wrote:
In article <87************ @bsb.me.uk>,
Ben Bacarisse <be********@bsb .me.ukwrote:
You miss my point. Conservative GC is always "safe" since anything that
even looks like a reference will prevent memory from being freed

In C, you do have to keep pointers as things that look like a
IRRTYM you _don't_ have to.
reference. You can memcpy() the bits of a pointer and shuffle them
up, wait a while, then unshuffle them and store them back in a
pointer. You can even print them out to a file. No GC is going to
handle that unaided.
- formerly david.thompson1 || achar(64) || worldnet.att.ne t
Dec 2 '07 #85

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

Similar topics

2
1995
by: James S | last post by:
Hi, Basically I've been fighting with this code for a few days now and can't seem to work around this problem. Included is the output, the program I use to get this error and the source code for my wrapper. This is acually part of the project, libxmlconf on sourceforge. The newest working version isn't there yet, and cvs is lagged by 6 hours or so. So if you think you want to have a try at this I can tgz the source for you. My...
1
2339
by: Bob | last post by:
Are there any known applications out there used to test the performance of the .NET garbage collector over a long period of time? Basically I need an application that creates objects, uses them, and then throws them away and then monitors the garbage collection and store statistics on it, preferably in C#. I want to know what is the longest period of time that an application may lock up while garbage collection is processing. Thanks!
55
4185
by: jacob navia | last post by:
Tired of chasing free(tm) bugs? Get serious about C and use lcc-win32. The garbage collector designed by Boehm is the best of its class. Very simple: #define malloc GC_malloc #define free(a) (a=NULL) NICE isn't it?
4
12337
by: Chris | last post by:
Hi, I think I'm having some problems here with garbage collection. Currently, I have the following code: public struct Event { public int timestamp;
2
2118
by: C P | last post by:
I'm coming from Delphi where I have to explicitly create and destroy instances of objects. I've been working through a C#/ASP.NET book, and many of the examples repeat the same SqlConnection, SqlDataAdapter etc. objects, so I thought I'd create a class with a bunch of factory methods to create my classes for me. But, I'm unclear about how garbage collection works, and if it is safe to do this. It seems to compile, but am I asking for...
142
6872
by: jacob navia | last post by:
Abstract -------- Garbage collection is a method of managing memory by using a "collector" library. Periodically, or triggered by an allocation request, the collector looks for unused memory chunks and recycles them. This memory allocation strategy has been adapted to C (and C++) by the library written by Hans J Boehm and Alan J Demers. Why a Garbage Collector? -----------------------
350
11910
by: Lloyd Bonafide | last post by:
I followed a link to James Kanze's web site in another thread and was surprised to read this comment by a link to a GC: "I can't imagine writing C++ without it" How many of you c.l.c++'ers use one, and in what percentage of your projects is one used? I have never used one in personal or professional C++ programming. Am I a holdover to days gone by?
3
275
by: timothytoe | last post by:
Microsoft fixed some garbage collection problems in IE6 almost a year ago. I'm trying to figure out if many users of IE6 are unpatched and still have the old buggier JScript in them. I have a rather large ECMAScript app that is speedy enough in just about every browser but IE6. Some people tell me just to forget IE6, but it still seems to have significant share at www.w3schools.com. And anecdotally, the place my brother works...
158
7910
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is discouraged due to some specific reason. If someone can give inputs on the same, it will be of great help. Regards, Pushpa
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.