Page 1 of 1

memory_limit doesn't affect imagecreatetruecolor?

Posted: Tue Oct 17, 2006 5:55 pm
by dbevfat
I was playing around and tried to allocate an extremely large image with imagecreatetruecolor(10000, 10000) to deliberately hit the memory limit on my server (8MB).

When I ran the script, it started consuming memory, then the script stalled, returned nothing, and the memory was freed. No "memory limit hit" message from PHP though, and memory usage of the script reached over 1GB (the script alone, not total memory usage on my system).

Does this mean that imagecreatetruecolor() doesn't obey the memory limit, or did I just miss something?

Posted: Tue Oct 17, 2006 5:59 pm
by Weirdan
hmm.... it seems so. what does return memory_get_peak_usage()? (you may need recent version of php to use this function).

Posted: Tue Oct 17, 2006 6:06 pm
by feyd
1K x 1K true color image is 4MB.

Posted: Tue Oct 17, 2006 6:11 pm
by dbevfat
Weirdan wrote:hmm.... it seems so. what does return memory_get_peak_usage()? (you may need recent version of php to use this function).
Will try, but I have WindowsXP at home, and I know some memory-related functions are not supported on Windows.
feyd wrote:1K x 1K true color image is 4MB.
True, and a 100x100 image is probably about 40KB. But a 10000x10000 image is 400MB (in theory) and over 1GB in practice.

Posted: Tue Oct 17, 2006 6:13 pm
by feyd
oops, I thought I saw 1000, not 10,000 in your post.

Posted: Tue Oct 17, 2006 6:20 pm
by dbevfat
feyd wrote:oops, I thought I saw 1000, not 10,000 in your post.
Happens, with all those 0's ... :)
Weirdan wrote:hmm.... it seems so. what does return memory_get_peak_usage()? (you may need recent version of php to use this function).
That function doesn't exist on PHP 5.1.6, which is the latest stable windows version. I'll try my gentoo server tomorrow.

Thanks