473,811 Members | 3,264 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 3560

"Tor Rustad" <to********@hot mail.comwrote in message
news:hJ******** *************@t elenor.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.
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.

to what extent standardization would make sense, would be in terms of a
"standardiz ed" definition of the API and provided functionality and
semantics (said, "portable" GC), but I do not expect by any means that it be
somehow "required" (as is the case with Java and C#, where GC is an assumed
and fundamental part of the language).

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

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


Nov 21 '07 #71
jacob navia wrote:
>
.... snip ...
>
This change doesn't look good for being able to use third party
libraries compiled with a different compiler...
You can't count on that anyhow. In fact, you expect failure.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home .att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Nov 21 '07 #72
Paul Hsieh wrote:
>
.... snip ...
>
It forces call stack uniformity (the EH needs to be able to crawl up
the stack and unwind the stack in a uniform way.) So for example,
To bring things back to reality, there is no reason to have a stack
in any C system.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home .att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com

Nov 21 '07 #73

"CBFalconer " <cb********@yah oo.comwrote in message
news:47******** *******@yahoo.c om...
jacob navia wrote:
>>
... snip ...
>>
This change doesn't look good for being able to use third party
libraries compiled with a different compiler...

You can't count on that anyhow. In fact, you expect failure.
theoretically, yes.

in practicality, one is forced to deal with this issue.

for example, between windows and linux, there are any number of compilers
you can compile code with, and they can make dlls and static libraries.

if one makes their compiler incompatible, say, by using a different calling
convention, then they are unable to use really any code (static libraries,
DLLs, ...) for their platform, and the compiler becomes essentially useless.
so, on x86, there is a singular more or less mandatory calling convention
(cdecl), and on windows, another less-common but still mandatory convention
(stdcall).

on x86-64, there are 2 calling conventions, the SystemV x86-64 convention
(followed by linux and friends), and the Win64 calling convention (windows).

and, again, to be useful on these archs, one needs to support these
conventions (even as such, I have been vaguely tempted to just use my own
convention for x86-64, but this would require, of all horrors, stubbing, to
interface external code).

what convention would I use:
I would actually just "upgrade" the existing 32-bit x86 calling convention
to work on x86-64...
that or use the Win64 convention internally, which should not be too
difficult to support (would just need to come up with some means of creating
a Win64 to SysV adaptor interface...).

or such...

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home .att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Nov 21 '07 #74

"CBFalconer " <cb********@yah oo.comwrote in message
news:47******** *******@yahoo.c om...
Paul Hsieh wrote:
>>
... snip ...
>>
It forces call stack uniformity (the EH needs to be able to crawl up
the stack and unwind the stack in a uniform way.) So for example,

To bring things back to reality, there is no reason to have a stack
in any C system.
errm?...

what kind of 'reality' is it you are living in?...
I guess it is theoretically possible, but it would lead to incompatibility
and what reason is there that anyone should implement such a thing?...

I guess, maybe you mean, all the call-frames are allocated on the heap, but
then one has to totally re-engineer the calling conventions, recompile all
the libraries, and likely deal with a pretty damn major performance hit.
I guess it could allow things like scheme style continuations, lazy
evaluation, and simplify using fine-grained concurrency (no more "threads",
only 'workers' and 'work queues').
the fact that pretty much every arch has a stack, and those that don't, fake
it, this is telling of its relevance...

Nov 21 '07 #75
cr88192 wrote:
"CBFalconer " <cb********@yah oo.comwrote in message
news:47******** *******@yahoo.c om...
>Paul Hsieh wrote:
... snip ...
>>It forces call stack uniformity (the EH needs to be able to crawl up
the stack and unwind the stack in a uniform way.) So for example,
To bring things back to reality, there is no reason to have a stack
in any C system.

errm?...

what kind of 'reality' is it you are living in?...

Mr Falconer has his own world, as many people here around.

A stack is not necessary, one complement or sign magnitude
representations rule the world, etc etc.

I think we have touched a trap representation
:-)

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Nov 21 '07 #76
In article <fi**********@a ioe.org>, jacob navia <ja***@nospam.c omwrote
on Wednesday 21 Nov 2007 7:05 pm:
cr88192 wrote:
>"jacob navia" <ja***@nospam.c omwrote in message
news:fi******* ***@aioe.org...
<snip>
>but, it is maybe interesting from a theoretical perspective, aka:
a C-implementation allocating all the call frames on a heap.

so, we want a call frame?
grab it from a free-list (or, somehow, allocate more if needed).

need to store locals? grab a chunk of memory for this and attach to
call frame.
need space for args? likewise, grab a chunk of memory, evaluate and
store in the args, and attach it to the (newly created) call frame of
the function being called.

So, you are implementig the stack in software. Instead of doing a
single register subtract, you allocate memory, put that in the list
of active frames, etc etc!

That would be really bad for performance
I think that with a lot of restrictions on usage a software stack can
compete reasonably well with a hardware one. The actual memory is very
likely to be held in the CPU caches and the machine instructions to
manipulate the stack are also likely to be very similar.

Of course, using a software stack when dedicated hardware support is
available is probably unnecessary unless special flexibility is needed.

And it's not within the spirit of C, as I understand it, to chose
inefficient means to do what _can_ be done more efficiently, time and
space wise.

<snip>

Nov 21 '07 #77

"santosh" <sa*********@gm ail.comwrote in message
news:fi******** **@registered.m otzarella.org.. .
In article <fi**********@a ioe.org>, jacob navia <ja***@nospam.c omwrote
on Wednesday 21 Nov 2007 7:05 pm:
>cr88192 wrote:
>>"jacob navia" <ja***@nospam.c omwrote in message
news:fi****** ****@aioe.org.. .

<snip>
>>but, it is maybe interesting from a theoretical perspective, aka:
a C-implementation allocating all the call frames on a heap.

so, we want a call frame?
grab it from a free-list (or, somehow, allocate more if needed).

need to store locals? grab a chunk of memory for this and attach to
call frame.
need space for args? likewise, grab a chunk of memory, evaluate and
store in the args, and attach it to the (newly created) call frame of
the function being called.

So, you are implementig the stack in software. Instead of doing a
single register subtract, you allocate memory, put that in the list
of active frames, etc etc!

That would be really bad for performance

I think that with a lot of restrictions on usage a software stack can
compete reasonably well with a hardware one. The actual memory is very
likely to be held in the CPU caches and the machine instructions to
manipulate the stack are also likely to be very similar.

Of course, using a software stack when dedicated hardware support is
available is probably unnecessary unless special flexibility is needed.

And it's not within the spirit of C, as I understand it, to chose
inefficient means to do what _can_ be done more efficiently, time and
space wise.
yes, I agree...

what I was writing about was actually, something a little odd, namely
compiling C in a way very much unlike C...
in effect, it would be compiling C like it were scheme.

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

this is because, with a non-linear memory structure, we can determine, for
example, that something in a function will "capture" the state from that
function (such as the current continuation, part of the lexical scope, ...).
as a result, when the function returns (after this capture has occured), the
call or environment frames are not released (this is possible to determine
statically because things like 'lambda' or 'call/cc' are visible lexically,
though special considerations exist for call/cc).

this is not too terrible of a problem, since, the memory layout is
non-linear, later calls simply use different frames and different memory.
of course, probably a better approach performance-wise would be to switch
out the approach, and only really use call-frames in the case where closures
or continuations are used (closures are easier than continuations, because
although closures are always visible lexically, the use of a continuation
may not be).

luckily, the most common use of a continuation is to implement something
analogous to longjmp (said 'partial' or 'exit-only' continuations). these do
not require as much in terms of special treatment.

but, usage of full continuations are a problem, since they apply potentially
to the entire call graph.

another common approach, makes code itself fast, but call/cc very expensive.
this is an approach focusing around saving/restoring the stack (call/cc
saves the stack, and using a continuation restores it). another approach I
have heard of, is to implement each continuation as a seperate thread (how
this is done in practice I am less certain of, the basic idea is that
call/cc either forks or spawns duplicate threads, and invoking a
continuation causes executon to continue from that thread, or something...).

or such...

<snip>

Nov 21 '07 #78
cr88192 wrote:
"Tor Rustad" <to********@hot mail.comwrote in message
news:hJ******** *************@t elenor.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.

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

--
Tor <bw****@wvtqvm. vw | tr i-za-h a-z>
Nov 21 '07 #79
On Nov 20, 6:51 pm, CBFalconer <cbfalco...@yah oo.comwrote:
Paul Hsieh wrote:
... snip ...
It forces call stack uniformity (the EH needs to be able to crawl up
the stack and unwind the stack in a uniform way.) So for example,

To bring things back to reality, there is no reason to have a stack
in any C system.
Not only are you wrong, but you preface it in a way that makes you
even wronger. Amazing.

Functions calls are to push as return is to pop. It might not be
*called* a stack, but it *IS* a stack, and this has nothing to do with
system implementation details. The C *STANDARD* implicitly implements
a stack.

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.

You may have meant that you don't need a particular implementation of
a hardware stack. But that's irrelevant to the point I am making. 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.

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. If you throw/raise at this point, you expect catch #1 to be
triggered -- not catch #2, and not vacated entirely (and simply
leading to a runtime error.) That means these catches must exist at
each level of the call stack.

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/
Nov 21 '07 #80

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

Similar topics

2
1996
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
2340
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
4186
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
12341
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
2119
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
6879
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
11952
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
7921
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
9727
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
9605
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,...
1
10398
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10133
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
7669
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
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
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
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.