How far can stack [LIFO] solve do automatic garbage collection and prevent memory leak ?

John Bokma john at castleamber.com
Tue Aug 24 19:53:26 EDT 2010


Hugh Aguilar <hughaguilar96 at yahoo.com> writes:

> On Aug 22, 11:12 am, John Bokma <j... at castleamber.com> wrote:
>
>> And my
>> experience is that a formal study in CS can't compare to home study
>> unless you're really good and have the time and drive to read formal
>> books written on CS. And my experience is that most self-educaters don't
>> have that time.
>
> I've read a lot of graduate-level CS books. I think most self-educated
> programmers have read more of these books than have 4-year degree
> students who were not required to in order to get their Bachelors
> degree and who were too busy during college to read anything that
> wasn't required.

I doubt it. But this all comes back to what I earlier wrote: those with
a CS degree think they are better than people without, and people
without think they can achieve the same or better by just buying a few
books and reading them. On top of that, most of the people I knew in my
final year were very fanatic regarding CS: it was a hobby to
them. During coffeebreaks we talked about approximation algorithms for
TSPs for example. Not always, but it happened. I read plenty of books
during my studies that were not on the list, as did other students I
knew.

If I recall correctly, you don't have a CS degree. I do, and I can tell
you that your /guess/ (since that is all it is) is wrong. For most exams
I've done one had not only to have read the entire book (often in a very
short time), but also the hand-outs. And for quite some courses
additional material was given during the course itself, so not attending
all classes could result in a lower score. Reading additional books and
papers helped. Sometimes reading a book by a different author could be a
real eye opener (and the students I had contact with did exactly this).

On top of that, often in class excercises were done, and with some
courses I had to hand in home work (yikes).

Also, most books are easy to read compared to CS papers. In my final two
years I did several courses which solely consisted of reading a CS paper
and giving a presentation on the subject in front of your classmates
(and sometimes other interested people). Reading and understanding such
a paper is one (and quite an effort). Teaching it in front of a (small)
class within a few days is not easy, to say the least. We also had to
attend several talks by guest speakers. I went to more than the required
number, including a guest talk by Linus. When there was a break-through
in proving Fermat's last theorem there was a talk, which I attended,
like several other class mates.

I am sure there are students who are there just to get a degree and to
make money. But my class mates didn't fall into that category, or I have
missed something.

So yes, I am convinced that there are plenty of self-educated people who
can code circles around me or plenty of other people with a CS
degree. But IMO those people are very hard to find. Most people
overestimate their skills, with or without a degree; I am sure I do. And
it wouldn't surprise me if self-educated people do this more so.

>> On the other hand: some people I knew during my studies had no problem
>> at all with introducing countless memory leaks in small programs (and
>> turning off compiler warnings, because it gave so much noise...)
>
> I do this all the time. My slide-rule program, for example, has beau-
> coup memory leaks. When I have time to mess with the program I clean
> up these memory leaks, but it is not a big deal. The program just
> runs, generates the gcode and PostScript, and then it is done. I don't
> really worry about memory leaks except with programs that are run
> continuously and have a user-interface, because they can eventually
> run out of memory.

Oh boy, I think you just made my point for me...

> The real problem here is that C, Forth and C++ lack automatic garbage
> collection. If I have a program in which I have to worry about memory
> leaks (as described above), I would be better off to ignore C, Forth
> and C++ and just use a language that supports garbage collection.

Several languages that support garbage collection still are able to leak
memory when circular datastructures are used (for example). Also,
allocating memory and never giving it back (by keeping a reference to
it) can also be memory leaking. And the wrong form of optimization can
result in a program using more memory than necessary. On top of that,
you have to understand when the gc releases memory, and things like
memory fragmentation. In short: you still have to use your head (on some
occasions even more).

> Why should I waste my time carefully freeing up heap space? I will
> very likely not find everything but yet have a few memory leaks
> anyway.

Why should you waste time with carefully checking for other issues? In
my experience, once you become sloppy with one aspect it's very easy to
become sloppy with others as well.

-- 
John Bokma                                                               j3b

Blog: http://johnbokma.com/    Facebook: http://www.facebook.com/j.j.j.bokma
    Freelance Perl & Python Development: http://castleamber.com/



More information about the Python-list mailing list