Fill memeory with endless loop?

G

globalrev

if i do something like
while 1:
print "x"

will the program ever stop because it runs out of memory? or is the
print x never stored somewhere?
if u do soemhting like add element to a list it has an upper nbr of
elements right? if though huge...
does windows or any other OS have some proces that would stop
something like this after a while? could be interpreted a s a virus
perhaps?
 
F

Filip Štědronský

if i do something like
while 1:
print "x"

will the program ever stop because it runs out of memory?

No, there is no reason to run out of memory. This will simply
make an everlasting x-printer and there is no need to store
anything (except output buffers, terminal scrollback, etc.,
but all of this is temporary and of limited size). In case of
adding elements to a list, the memory usage can, of course,
grow unlimitedly. On linux, if the process eats up too much
memory, it gets killed. I do not know about windows, but
they would probably crash with a BSOD or something of that
sort.
 
M

Mensanator

No, there is no reason to run out of memory. This will simply
make an everlasting x-printer and there is no need to store
anything (except output buffers, terminal scrollback, etc.,
but all of this is temporary and of limited size). In case of
adding elements to a list, the memory usage can, of course,
grow unlimitedly. On linux, if the process eats up too much
memory, it gets killed. I do not know about windows, but
they would probably crash with a BSOD or something of that
sort.

Usually, Windows just says "out of memory".
 
G

globalrev

No, there is no reason to run out of memory. This will simply
make an everlasting x-printer and there is no need to store
anything (except output buffers, terminal scrollback, etc.,
but all of this is temporary and of limited size). In case of
adding elements to a list, the memory usage can, of course,
grow unlimitedly. On linux, if the process eats up too much
memory, it gets killed. I do not know about windows, but
they would probably crash with a BSOD or something of that
sort.


and when the program get skiled because out of memory all this will be
deleted from the memory?

so there is no way that you can, by accident, fill your whole
harddrive and make it unusable?

and RAM-memory always get cleaned out when not used i guess?
 
G

Gabriel Genellina

if i do something like
while 1:
print "x"
will the program ever stop because it runs out of memory?

No, there is no reason to run out of memory. This will simply
make an everlasting x-printer and there is no need to store
anything [...]

and when the program get skiled because out of memory all this will be
deleted from the memory?

Yes. That's the operating system job.
so there is no way that you can, by accident, fill your whole
harddrive and make it unusable?

and RAM-memory always get cleaned out when not used i guess?

We were talking of RAM, including virtual memory backed by disk space.
You *may* fill your whole disk if you keep writing data. If you invoke
your example above using:
python neverending.py > output
the "output" file will grow indefinitely until you kill the program or you
get a "disk full" exception.
That disk space is not cleared when the program exits - you have to
explicitely delete the file.
Note that none of this is Python specific.
 
T

Tim Roberts

globalrev said:
and when the program get skiled because out of memory all this will be
deleted from the memory?

Yes. When a process is killed, all of the memory it was using is released.
so there is no way that you can, by accident, fill your whole
harddrive and make it unusable?

Of course not. Where do you see a connection between memory and your hard
drive?

Now, you can certainly fill your hard drive by running your little infinite
loop application and storing the results in a file:
python looper.py > saveme.txt
but I hope it is clear to you that this can't damage any of the data you
already have.
and RAM-memory always get cleaned out when not used i guess?

It gets released so that it can be re-used. I don't know what you mean by
"cleaned out". Remember that most of the systems where Python runs are
virtual memory systems, so even if one application is using a couple of
gigabytes of memory, other applications are still able to run.
 
B

Bruno Desthuilliers

Tim Roberts a écrit :
Yes. When a process is killed, all of the memory it was using is released.


Of course not. Where do you see a connection between memory and your hard
drive?

swap.

But that won't "fill your whole harddrive", indeed !-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top