goldensona — 2013-01-28T01:42:44-05:00 — #1
i want to know about how the php handle memory allocation, if i use the oops concept how the allocated object memory will free ,it will automatically , can any one tell about this. how we use effective memory utilization in php.
michael_morris1 — 2013-01-28T13:30:26-05:00 — #2
PHP doesn't allow you to directly access the memory. You can monitor memory consumption during the script and use unset to manually clear variables you know you aren't going to use, though PHP's garbage collection will wipe these eventually anyway. Your question does raise the red light of "are you sure PHP is the language to use for this?" because memory management is typically the last consideration of most PHP scripts, and some of the most popular are veritable pigs with memory (here's looking at you Magento).
2ndmouse — 2013-01-28T14:39:00-05:00 — #3
This has worked for me in the past:
starlion — 2013-01-28T14:51:28-05:00 — #4
ew. Good way to have your server overload.
kylewolfe — 2013-01-28T14:56:06-05:00 — #5
Might be worth reading: http://www.tuxradar.com/practicalphp/18/1/10
Most of my scripts use a recursion that uses that same variables over and over again. Most operations done in PHP aren't dealing with objects large enough to have a significant impact on your memory usage. There is a garbage collection function as of 5.3 something, though, which i have yet to find the need to use yet.
2ndmouse — 2013-01-28T14:59:56-05:00 — #6
Ok, fair point - maybe '-1' is a bit drastic, but it could be used with a specific value:
goldensona — 2013-01-29T00:39:10-05:00 — #7
if i use 50mb in limit, i can use only 50mb if my application want to user more than that what will happen, i want to make sure if i didnt unset the unused variable,mysql free result it will automatically clear when the script end ,my understanding is correct ?. else it will raise memory problem.
2ndmouse — 2013-01-29T03:15:07-05:00 — #8
Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.
quoted from PHP.net so you don't need to worry about unsetting.
ini_set("memory_limit","50m"); sets an upper limit of 50mb - you need to know roughly what your upper limit is for this to work satisfactorily.
goldensona — 2013-01-29T04:04:18-05:00 — #9
ok thanks for your suggestion. i dont want to specify by setting,whether php manage automatic garabage collection , while doing code i have to do memory release ?
starlion — 2013-01-29T08:36:36-05:00 — #10
What exactly are you doing that would require more than 50 MB of memory usage? o.O
michael_morris1 — 2013-01-29T08:57:48-05:00 — #11
Large image manipulation - that's all I've got. That or he's running Magento.
goldensona — 2013-01-29T22:55:39-05:00 — #12
just i want to know about it .