7

I have a rather large PHP script that is leaking memory. I have been able to figure out what object is leaking, but I have not been able to find out where in the script it is leaking. Some part of my script is keeping a reference to the leaking object.

Is there some way that I can track (and preferably backtrace) where/when a PHP object has it's reference count increased or decreased?

2 Answers 2

2

You can use profiling tools to find out what is leaking your memory i prefer http://xdebug.org/ and http://code.google.com/p/webgrind

http://derickrethans.nl/xdebug-and-tracing-memory-usage.html

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I am familliar with XDebug and function tracing. But do you know how I can use it to track where my leaking object is referenced from in my code?
you can try to track with webgrind it will show you all your invoked functions-methods, it wont show memory usage, but i think you may track them by time spent-usage
1

Try to use:

Also, I suggest to write the code in a easy-to-debug manner and separate the debugging procedures from the code.

3 Comments

I have already used XDdebug to find out what object is leaking. What I want to know now is where it is leaking? I.e. where in my code are references to that object kept? Can XDebug be used for that?
How do you used the breakpoints to locate where the object is leaking? Hard to come with a "general" solution.
Hence my question. I had hoped there was some kind of way to track or trigger when the Zend Engine increments or decrements an object's internal reference count.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.