php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61014 Memory leak on unserialize for certain nested objects
Submitted: 2012-02-08 16:24 UTC Modified: 2013-07-30 20:03 UTC
From: npm at nuestrared dot com Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 5.4SVN-2012-02-08 (snap) OS: Debian Linux
Private report: No CVE-ID: None
 [2012-02-08 16:24 UTC] npm at nuestrared dot com
Description:
------------
Unserializing certain objects on a loop, incurs in increased memory consumption 
even when the garbage collector is enables and gc_collect_cycles() is called 
after each iteration.  

For the test script there is an increase of almost 5MB, after 100 runs, it 
doesn't happen with every object, but it does with the one on the test. 
The increase is not with every iteration but every couple of iterations, until it 
reaches a maximum, in this case the 4980736 bytes.

This report is related to bug #60937, I had no reply on my comments.
Thanks,

Test script:
---------------
The test script can be found at:
http://dl.dropbox.com/u/7170408/unserialize_memleak.php

Expected result:
----------------
Consistent memory usage.

Actual result:
--------------
The output of the script:

Iteration 0	 Start Mem 786432 Cicle Mem 3145728 Diff 2359296
Iteration 1	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 2	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 3	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 4	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 5	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 6	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 7	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 8	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 9	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 10	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 11	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 12	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 13	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 14	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 15	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 16	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 17	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 18	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 19	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 20	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 21	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 22	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 23	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 24	 Start Mem 786432 Cicle Mem 5505024 Diff 4718592
Iteration 25	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 26	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 27	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 28	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 29	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 30	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 31	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 32	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 33	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 34	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 35	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 36	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 37	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 38	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 39	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 40	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 41	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 42	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 43	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 44	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 45	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 46	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 47	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 48	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 49	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 50	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 51	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 52	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 53	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 54	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 55	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 56	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 57	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 58	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 59	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 60	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 61	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 62	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 63	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 64	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 65	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 66	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 67	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 68	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 69	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 70	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 71	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 72	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 73	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 74	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 75	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 76	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 77	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 78	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 79	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 80	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 81	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 82	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 83	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 84	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 85	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 86	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 87	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 88	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 89	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 90	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 91	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 92	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 93	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 94	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 95	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 96	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 97	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 98	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Iteration 99	 Start Mem 786432 Cicle Mem 5767168 Diff 4980736
Done.

Start Mem 786432 End Mem 5767168 Final Diff 4980736

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-08 19:02 UTC] carloschilazo at gmail dot com
I'm not sure the problem is on the unserialize function;

I saved the value of $str (after gzuncompress/base64_decode) (so I got the 
original serialized string, and hardcoded it on the script)

Then ran the script and got consistent memory usage...
 [2012-02-09 11:51 UTC] npm at nuestrared dot com
Hi, if you got consistent memory usage, it is probable that your saved string 
cannot be unserialized correctly, try printing it or turn on PHP errors to see if 
the unserialize was correct.
 [2013-07-30 20:03 UTC] mike@php.net
-Status: Open +Status: Not a bug
 [2013-07-30 20:03 UTC] mike@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Dup of Bug #60937
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 03 20:01:29 2024 UTC