/    Sign up×
Community /Pin to ProfileBookmark

Showing memory use of all variables or similar?

Hi

I made a script that loops through a textfile and for each line I call a function in an included php-script which I didn’t make. Memory consumption is increasing drastically when I’m running the script. It takes several hours, and I guess it will hit the memory roof after a while and I suppose there’s something in the function I call that are doing this (some variables not freed or something).

Is there a way to see what (variables) are taking what amount of memory? Is it possible to free memory without knowing what’s going on in the “external” function? Btw: there’s actually not much I can do with that function.

Thanks
Lubox

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 21.2009 — memory_get_usage() can tell you how much memory is being used at any given point in the script. Other than that, I don't know of anything that specifically looks at memory usage for a given variable. strlen() for any scalar string variable should give you a good idea, whereas arrays might need some sort of looping and/or recursive function.
Copy linkTweet thisAlerts:
@MindzaiOct 21.2009 — I also like the xdebug extension, it can give you some useful memory related info along with stack traces.
Copy linkTweet thisAlerts:
@LuboxauthorOct 22.2009 — Should looking at $GLOBALS give me information about everything? If I print it to a file every now and then, it shows almost the exact same information even though the memory consumption of php.exe has gone from 10 MB to 60 MB....
Copy linkTweet thisAlerts:
@NogDogOct 22.2009 — Should looking at $GLOBALS give me information about everything? If I print it to a file every now and then, it shows almost the exact same information even though the memory consumption of php.exe has gone from 10 MB to 60 MB....[/QUOTE]

It would only show variables in the global scope, so possibly there could be something within a function scope, for example, that would not show up.
Copy linkTweet thisAlerts:
@LuboxauthorOct 22.2009 — It would only show variables in the global scope, so possibly there could be something within a function scope, for example, that would not show up.[/QUOTE]

But wouldn't data in a function scope be removed from memory when exiting that function? Or do variables in a function need to be unset to actually remove them?
Copy linkTweet thisAlerts:
@NogDogOct 22.2009 — Yes, when a function returns it should release all local variables. I'm just pointing out possibilities. Could be the same thing with class/object variables (which should be released when the object is destroyed.

Other things to possibly look at are files read into variables then not unset() when done with them (I'm not sure how smart the PHP compiler is about release such variables when they're no longer needed), or query result sets, perhaps.
×

Success!

Help @Lubox spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...