Bugs item #1524938, was opened at 2006-07-19 05:46
Message generated for change (Comment added) made by markmat
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1524938&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Feature Request
Status: Open
Resolution: None
Priority: 5
Submitted By: Mark Matusevich (markmat)
Assigned to: Nobody/Anonymous (nobody)
Summary: PEP MemoryError with a lot of available memory gc not called

Initial Comment:
Also the gc behavior is consistent with the
documentation, I beleave it is wrong. I think, that Gc
should be called automatically before any memory
allocation is raised.

Example 1:
for i in range(700): 
   a = [range(5000000)]
   a.append(a)
   print i

This example will crash on any any PC with less then
20Gb RAM. On my PC (Windows 2000, 256Mb) it crashes at
i==7.
Also, this example can be fixed by addition of a call
to gc.collect() in the loop, in real cases it may be
unreasonable. 


----------------------------------------------------------------------

>Comment By: Mark Matusevich (markmat)
Date: 2006-08-03 13:02

Message:
Logged In: YES 
user_id=1337765

Another problem related to the above example: there is a
time waste due to a memory swap before the MemoryError. 
Possible solution is to use a dynamic memory limit: GC is
called when the limit is reached, then the limit is adjusted
according to the memory left.


----------------------------------------------------------------------

Comment By: Jim Jewett (jimjjewett)
Date: 2006-08-03 00:52

Message:
Logged In: YES 
user_id=764593

Doing it everywhere would be a lot of painful changes.

Adding the "oops, failed, call gc and try again" to to 
PyMem_* (currently PyMem_Malloc, PyMem_Realloc, PyMem_New, 
and PyMem_Resize, but Brett may be changing that) is far 
more reasonable.

Whether it is safe to call gc from there is a different 
question.

----------------------------------------------------------------------

Comment By: Mark Matusevich (markmat)
Date: 2006-07-23 23:19

Message:
Logged In: YES 
user_id=1337765

Sorry, my last comment was to illume (I am slow typer :( )

----------------------------------------------------------------------

Comment By: Mark Matusevich (markmat)
Date: 2006-07-23 23:11

Message:
Logged In: YES 
user_id=1337765

This is exectly what I meant. 
For my recollection, this is the policy in Java GC. I never
had to handle MemoryError in Java, because I knew, that I
really do not have any more memory.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2006-07-23 23:00

Message:
Logged In: YES 
user_id=21627

This is very difficult to implement. The best way might be
to introduce yet another allocation function, one that
invokes gc before failing, and call that function in all
interesting places (of which there are many).

Contributions are welcome and should probably start with a
PEP first.

----------------------------------------------------------------------

Comment By: Rene Dudfield (illume)
Date: 2006-07-20 02:20

Message:
Logged In: YES 
user_id=2042

Perhaps better than checking before every memory allocation,
would be to check once a memory error happens in an allocation.

That way there is only the gc hit once there is low memory.

So...

res = malloc(...);
if(!res) {
    gc.collect();
}

res = malloc(...);
if(!res) {
    raise memory error.
}





----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1524938&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to