Ticket #4709 (closed enhancement: fixed)

Opened 1 year ago

Last modified 1 year ago

Free up memory by using imagedestroy() in wp_create_thumbnail()

Reported by: Viper007Bond Assigned to: anonymous
Priority: normal Milestone: 2.5
Component: Optimization Version: 2.3
Severity: normal Keywords:
Cc:

Description

I noticed that wp_create_thumbnail() (and possibly other image handling functions) doesn't make use of imagedestroy() to destroy the temporary image that's in memory once it's done with it.

While this is automatically done when the PHP file is done running, I think it'd be good to do it ourselves as soon as we're done with $thumbnail, i.e. as soon as we save it.

Less memory usage == good, right? Or am I a noob and missing something?

Attachments

image.diff (340 bytes) - added by Viper007Bond on 08/07/07 10:08:11.

Change History

08/07/07 10:08:11 changed by Viper007Bond

  • attachment image.diff added.

08/07/07 13:57:36 changed by Otto42

The thumbnail takes up almost no memory. If you want to really free up memory, you should do imagedestroy($image) immediately after the call to imagecopyresampled. $image is the full sized image which was loaded into memory, the resulting $thumbnail is tiny by comparison.

While all this is likely unnecessary, I agree that it's a good idea for the wp_create_thumbnail functions to cleanup after themselves a bit better, since it's possible that plugins and/or other code may attempt to use these directly. WordPress doesn't need this code itself in most cases, but it won't hurt anything to have it there and it might help reduce some people's out-of-memory issues.

08/09/07 10:33:47 changed by Viper007Bond

Er, yeah, the thumbnail would (usually) be small.

I noticed all of this though as I use this function a lot for resizing / thumbnailing in plugins I've been writing for a client and those images uploaded could be a couple MB.

09/02/07 19:29:56 changed by foolswisdom

  • milestone changed from 2.3 to 2.4 (next).

11/03/07 18:33:20 changed by westi

  • status changed from new to closed.
  • resolution set to fixed.

(In [6309]) Refactor of wp-admin/includes/image.php. Fixes #5312, #4151, #4709, #5304 props DD32.