Monday 30 March 2020

Trying to understand class instances

I am trying to wrap my head around class instances and garbage collection.If I request a row from a database and store its fields in an object in memory, I understand that it makes most sense to use a new instance of a class to for example store user data in a user instance. My question is if I have multiple users using my app at the same time, and I create a user object for every one of them when they log into the site, how do I make sure the variable values in my function don't get overwritten by a new user instance that's using the same code while I'm waiting for an async operation to finish? And if that user object is then not in use anymore, how will the garbage collector now that it is not in use anymore if the code is still referencing that object from certain functions?

Submitted March 30, 2020 at 09:34PM by louissugar

No comments:

Post a Comment