Ticket #4709 (closed enhancement: fixed)

Opened 5 years ago

Last modified 4 years ago

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

Reported by: Viper007Bond Owned by: 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 Download (340 bytes) - added by Viper007Bond 5 years ago.

Change History

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.

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.

  • Milestone changed from 2.3 to 2.4 (next)
  • 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.

Note: See TracTickets for help on using tickets.