guyfromfl Posted May 12, 2011 Share Posted May 12, 2011 What happens if you do not unset an array before the script is done executing? I am running through thousands of CSV files, parsing data for hundreds of thousands of customers. It works fine for the first 5/6 hours then starts bogging down bad. I run about 5-10 CSVs per execution...I'm wondering if unsetting the arrays in the script would help this or not...I thought they would be unallocated after the script ends. Am I wrong? Quote Link to comment https://forums.phpfreaks.com/topic/236256-php-memory-question/ Share on other sites More sharing options...
btherl Posted May 13, 2011 Share Posted May 13, 2011 Yes, all data is deallocated when the script finishes, assuming you are using a standard setup. If you're paranoid you can unset the arrays yourself, which can save memory during that script run. For example: $data = get_data(); $processed_data = process_data($data); $more_processed_data = process_data_some_more($processed_data); At the end of these 3 statements you have 3 arrays in memory. You can save memory by unsetting the original arrays as soon as they are no longer needed (assuming they are not required later of course). Unless a variable is overwritten (and therefore inaccessible), unset, or goes out of scope, php must keep it around in case it gets accessed later. Another option when processing large volumes of data is to pass arrays by reference (this must be declared in the function definition) and modify them in-place. Quote Link to comment https://forums.phpfreaks.com/topic/236256-php-memory-question/#findComment-1214765 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.