[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ProgSoc] Deterministic destruction of objects in garbage-collected languages
Hello, I thought I'd break the monotony of all the penis-enlargement
spam (I'm sure, as programmers, that we're all capably well-endowed here
to a greater or lesser metaphorical extent) by posting a programming
question.
Does anyone have any opinion on the topic? I've been having problems
ensuring that destructors get called in a timely fashion in Python, and
from what I understand this is because I shouldn't expect that they get
called in a timely fashion at all. This is mostly not a problem but
sometimes it is a major problem (the case I was dealing with involved a
pool of database connections in a long-running server).
It seems to me that new Python features such as the "with" keyword are
essentially replacements for __del__, to minimise the impact of
non-deterministic finalisers. Take the file closing example from here as
an example:
http://docs.python.org/whatsnew/pep-343.html
Of course, "with" is also a whole bunch of other things too.
But I don't have much experience with GC languages other than Python (I
also know a bit of Java). How do other languages do it? Garbage
collection vs deterministic finalisation is probably an old chestnut on
comp.lang.python, but I haven't been paying much attention recently.
It seems that, for now, I should explicitly call the object's destructor
if I am finished with the object. This means that the destructor must be
very careful (checking each object attribute before referencing it, for
example) because it will be called twice. But in Python, destructors
must do this anyway (because there could have been an exception during
__init__), so it doesn't seem that bad.
- Nicholas
-
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to progsoc-request@xxxxxxxxxxxxxxxxxxx
If you are having trouble, ask owner-progsoc@xxxxxxxxxxxxxxxxxx for help.