Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #67964
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: script uses up all memory |
| Date | 2014-03-07 01:53 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <878usmrijk.fsf@elektro.pacujo.net> (permalink) |
| References | (4 earlier) <mailman.7879.1394144925.18130.python-list@python.org> <87ha7bq7ls.fsf@elektro.pacujo.net> <mailman.7880.1394145824.18130.python-list@python.org> <87d2hyrkf4.fsf@elektro.pacujo.net> <mailman.7881.1394148716.18130.python-list@python.org> |
Chris Angelico <rosuav@gmail.com>:
> Can you give a useful example of a closure that does create a refloop?
Just the other day, I mentioned the state pattern:
class MyStateMachine:
def __init__(self):
sm = self
class IDLE:
def ding(self):
sm.open_door()
sm.state = AT_DOOR()
class AT_DOOR:
...
self.state = IDLE()
def ding(self):
self.state.ding()
So we have:
MyStateMachine instance
-> MyStateMachine instance.ding
-> IDLE instance
-> IDLE instance.ding
-> MyStateMachine instance
plus numerous others in this example alone.
In general, event-driven programming produces circular references left
and right, and that might come into wider use with asyncio.
I suspect generators might create circular references as well.
Any tree data structure with parent references creates cycles.
In fact, I would imagine most OO designs create a pretty tight mesh of
back-and-forth references.
Marko
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: script uses up all memory Chris Angelico <rosuav@gmail.com> - 2014-03-07 09:28 +1100
Re: script uses up all memory Marko Rauhamaa <marko@pacujo.net> - 2014-03-07 00:34 +0200
Re: script uses up all memory Chris Angelico <rosuav@gmail.com> - 2014-03-07 09:43 +1100
Re: script uses up all memory Marko Rauhamaa <marko@pacujo.net> - 2014-03-07 01:12 +0200
Re: script uses up all memory Chris Angelico <rosuav@gmail.com> - 2014-03-07 10:31 +1100
Re: script uses up all memory Marko Rauhamaa <marko@pacujo.net> - 2014-03-07 01:53 +0200
Re: script uses up all memory Chris Angelico <rosuav@gmail.com> - 2014-03-07 11:11 +1100
Re: script uses up all memory Marko Rauhamaa <marko@pacujo.net> - 2014-03-07 02:31 +0200
csiph-web