WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 6 years ago

#4709 closed enhancement (fixed)

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

Reported by: Viper007Bond Owned by:
Milestone: 2.5 Priority: normal
Severity: normal Version: 2.3
Component: Optimization Keywords:
Focuses: 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 (1)

image.diff (340 bytes) - added by Viper007Bond 7 years ago.

Download all attachments as: .zip

Change History (5)

Viper007Bond7 years ago

comment:1 Otto427 years ago

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.

comment:2 Viper007Bond7 years ago

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.

comment:3 foolswisdom7 years ago

  • Milestone changed from 2.3 to 2.4 (next)

comment:4 westi6 years ago

  • Resolution set to fixed
  • Status changed from new to closed

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

Note: See TracTickets for help on using tickets.