[wp-trac] [WordPress Trac] #38285: Object lookups by ID (or primary key) are not managed properly, lots of memory leaks

WordPress Trac noreply at wordpress.org
Wed Oct 12 01:13:09 UTC 2016


#38285: Object lookups by ID (or primary key) are not managed properly, lots of
memory leaks
----------------------------+------------------------------
 Reporter:  wonderboymusic  |       Owner:
     Type:  defect (bug)    |      Status:  new
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Cache API       |     Version:
 Severity:  normal          |  Resolution:
 Keywords:                  |     Focuses:
----------------------------+------------------------------

Comment (by dd32):

 For what it's worth, the patch as-is is going to run into issues. Storing
 typed classes in the object cache has historically lead to hard-to-find
 bugs, and while it at first appears to work, it causes huge problems when
 you add a persistent cache (such as memcache) and then either migrate PHP
 (and don't flush the cache) or even worse when you change the class
 definition (and don't flush the cache) and the unserialized object is a
 hybrid of those two definitions (when it was stored, and when it was
 retrieved)

 I can't recall what the need for `clone` is, I suspect that's mostly for
 non-typed objects caching one thing, and then modifying it after.

 A hybrid approach might be to allow typed objects which specify a
 serializer/deserializer to be stored, only clone stdClass's, or something
 else entirely.

 To me, it feels like this might be better off handled higher than the
 cache, `WP_Post` having a static reference to all `WP_Post`'s it's
 created. Unfortunately I think that would mean memory usage would be
 doubled as there's no way from PHP-land to know that there's only one
 reference to that memory location left.

 The other alternative is waiting for PHP Future.Release to add a
 Comparable interface or something to allow comparing typed objects
 properly.

 However, there's other cases where you'd legitimately want two different
 objects of the same post, for example:
 {{{
 $post = get_post( 1 );
 modify_post( 1 );
 $modified_post = get_post( 1 );
 do_action( 'changed_something', $modified_post, $post );

 assertTrue( $post !== $modified_post );
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/38285#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list