jminardi / mecode

GCode for all
MIT License
221 stars 61 forks source link

Memory leak in serial mode #34

Open dreammaker opened 9 years ago

dreammaker commented 9 years ago

The following loop that simply moves back and forth will slowly consume more and more memory, presumably until it crashes.

g = G(direct_write_mode='serial')
while True:
    g.move(10, 0)
    g.move(-10, 0)

The problem is that the Printer class is storing every line ever sent in _buffer and doesn't clear it out until disconnecting.

DerAndere1 commented 5 years ago

Conservatively assuming 20 characters per G-code command, 1,000,000 G-code commands would require roughly 72 + (37+207+8 )1000000 bytes = 185000000 bytes = 185 MB for _buffer and another 185MB for the responses list (for calculation see https://code.tutsplus.com/tutorials/understand-how-much-memory-your-python-objects-use--cms-25609 ). If it is possible to replace those lists with ring buffers, that would be a nice change.