Copy link to clipboard
Copied
I have an app that uses several arrays as session variables. (There are good reasons why that I won't go into.) The arrays include a list of categories and a list of questions. The app loops through the categories, and with each iteration it redefines the question array and loads it with a set of questions. It uses the same array variable name each time: <cfset session.arrQuestion = ArrayNew(1)>.
This app could potentially have 200+ concurrent users, so server memory management is important here. My question is: Do I need to reclaim the memory ffrom the arrays with each iteration (at least the arrays that change) using StructDelete, or will each iteration use the same chunk of server memory because I'm using the same session variables each time?
Copy link to clipboard
Copied
If you are done using one of the session variables then you should structdelete it, but otherwise if you are overwriting it with another value, then the garbage collector will free the old array as long as there are no other references to it.
One way you may be able to make things more efficient would be to store all category data in the application scope instead, then you only have one copy per user (instead of replicating it). Then in your session varaible you only need to store the category id's relatvent to the user, and not all the additional data.
Copy link to clipboard
Copied
Thanks, Peter. That was very helpful. Just one other question: You say the garbage collector will free the old array as long as there are no other references to it. But since both the new and old arrays use the same session variable name, how does the garbage collector determine that there are no other references to it?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now