RE: [ACFUG Discuss] Destroy An Object
Thanks Cameron and Dean. The structDelete was what I was looking for! But Cameron, you made me think of another question when you mentioned calling init() on your user object. When do you create it? At the start of a session? Thanks again, Clarke -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Cameron Childress Sent: Wednesday, July 02, 2008 6:44 PM To: discussion@acfug.org Subject: Re: [ACFUG Discuss] Destroy An Object On Wed, Jul 2, 2008 at 6:20 PM, Clarke Bishop [EMAIL PROTECTED] wrote: I have a user object that's stored in the session scope when a user logs in. When the session expires, the object gets garbage collected, right? It's marked for GC, and eventually gets collected. Effectively as far as the app's concerned it's gone immediately. But, if I want to destroy the object, how do I do that? Maybe this is not something that's needed often as I couldn't find an answer via the docs or Google. A few options... To delete just that one item: cfset structDelete(session,'myUserObject') / However, I usually have a isLoggedIn property on the user object (with a default value of false) and do this: cfset session.myUserObject = createObject('component','path.to.User').init() / That way the user object still exists, but in recreating it you are resetting all the props to their default values, with the significant one here being isLoggedIn = false. -Cameron -- Cameron Childress Sumo Consulting Inc http://www.sumoc.com --- cell: 678.637.5072 aim: cameroncf email: [EMAIL PROTECTED] - To unsubscribe from this list, manage your profile @ http://www.acfug.org?fa=login.edituserform For more info, see http://www.acfug.org/mailinglists Archive @ http://www.mail-archive.com/discussion%40acfug.org/ List hosted by http://www.fusionlink.com - - To unsubscribe from this list, manage your profile @ http://www.acfug.org?fa=login.edituserform For more info, see http://www.acfug.org/mailinglists Archive @ http://www.mail-archive.com/discussion%40acfug.org/ List hosted by http://www.fusionlink.com -
Re: [ACFUG Discuss] Destroy An Object
On Thu, Jul 3, 2008 at 7:52 AM, Clarke Bishop [EMAIL PROTECTED] wrote: But Cameron, you made me think of another question when you mentioned calling init() on your user object. When do you create it? At the start of a session? It depends on the site's requirements to scale. On an internal site like an intranet I sometimes will create a new user object in the onSessionStart() in the Application CFC. This allows me to init() the user and know (for example) that the session.user.firstname property will always be present. This tends to prevent alot of time development time spent worrying about isDefined() or structKeyExists() calls. For a public site that gets more traffic like search engines, which spawn new sessions with each request, I usually use a Session Facade to keep my user's session and only init the object and put it in session when a user logs in. If they are unauthenticated, the facade might still genrate a Anonymous Visitor user object on the fly, or give me one that's stored in the application scope. That's really part of the beauty of the Session Facade pattern. The facade gives me an object for that user's session, but it might or might not come from the actual session scope. All the complexity is masked inside the Session Facade and all I care about outside the Session Facade is hey you there - give me a user object for the current request!, and it gives me one. My app doesn't care where it came from, just that it's there. Also, if anyone reading this is wondering, init() isn't some magic unknown thing in CF, it's just a method I always create (by convention) as a constructor in all my CFCs. I know that (according to my convention) that I should always call init() when I create an object instance, and that by calling that init() I know that all the properties inside the object will be set to their defaults. Would this stuff be a worthwhile topic for a meeting? Patterns? -Cameron -- Cameron Childress Sumo Consulting Inc http://www.sumoc.com --- cell: 678.637.5072 aim: cameroncf email: [EMAIL PROTECTED] - To unsubscribe from this list, manage your profile @ http://www.acfug.org?fa=login.edituserform For more info, see http://www.acfug.org/mailinglists Archive @ http://www.mail-archive.com/discussion%40acfug.org/ List hosted by http://www.fusionlink.com -
[ACFUG Discuss] Destroy An Object
I have a user object that's stored in the session scope when a user logs in. When the session expires, the object gets garbage collected, right? But, if I want to destroy the object, how do I do that? Maybe this is not something that's needed often as I couldn't find an answer via the docs or Google. Thanks, Clarke - To unsubscribe from this list, manage your profile @ http://www.acfug.org?fa=login.edituserform For more info, see http://www.acfug.org/mailinglists Archive @ http://www.mail-archive.com/discussion%40acfug.org/ List hosted by http://www.fusionlink.com -
Re: [ACFUG Discuss] Destroy An Object
On Wed, Jul 2, 2008 at 6:20 PM, Clarke Bishop [EMAIL PROTECTED] wrote: I have a user object that's stored in the session scope when a user logs in. When the session expires, the object gets garbage collected, right? It's marked for GC, and eventually gets collected. Effectively as far as the app's concerned it's gone immediately. But, if I want to destroy the object, how do I do that? Maybe this is not something that's needed often as I couldn't find an answer via the docs or Google. A few options... To delete just that one item: cfset structDelete(session,'myUserObject') / However, I usually have a isLoggedIn property on the user object (with a default value of false) and do this: cfset session.myUserObject = createObject('component','path.to.User').init() / That way the user object still exists, but in recreating it you are resetting all the props to their default values, with the significant one here being isLoggedIn = false. -Cameron -- Cameron Childress Sumo Consulting Inc http://www.sumoc.com --- cell: 678.637.5072 aim: cameroncf email: [EMAIL PROTECTED] - To unsubscribe from this list, manage your profile @ http://www.acfug.org?fa=login.edituserform For more info, see http://www.acfug.org/mailinglists Archive @ http://www.mail-archive.com/discussion%40acfug.org/ List hosted by http://www.fusionlink.com -
Re: [ACFUG Discuss] Destroy An Object
And to add to Cam's response: When you replace the object with a new instance, it is not destroyed immediately. However, you lose all references to it and it may now be garbage collected. You should never try to force the GC to run, the Java VM will handle it automagically for you when needed. -dhs Dean H. Saxe, CISSP, CEH [EMAIL PROTECTED] What difference does it make to the dead, the orphans, and the homeless, whether the mad destruction is wrought under the name of totalitarianism or the holy name of liberty and democracy? --Gandhi On Jul 2, 2008, at 6:44 PM, Cameron Childress wrote: On Wed, Jul 2, 2008 at 6:20 PM, Clarke Bishop [EMAIL PROTECTED] wrote: I have a user object that's stored in the session scope when a user logs in. When the session expires, the object gets garbage collected, right? It's marked for GC, and eventually gets collected. Effectively as far as the app's concerned it's gone immediately. But, if I want to destroy the object, how do I do that? Maybe this is not something that's needed often as I couldn't find an answer via the docs or Google. A few options... To delete just that one item: cfset structDelete(session,'myUserObject') / However, I usually have a isLoggedIn property on the user object (with a default value of false) and do this: cfset session.myUserObject = createObject('component','path.to.User').init() / That way the user object still exists, but in recreating it you are resetting all the props to their default values, with the significant one here being isLoggedIn = false. -Cameron -- Cameron Childress Sumo Consulting Inc http://www.sumoc.com --- cell: 678.637.5072 aim: cameroncf email: [EMAIL PROTECTED] - To unsubscribe from this list, manage your profile @ http://www.acfug.org?fa=login.edituserform For more info, see http://www.acfug.org/mailinglists Archive @ http://www.mail-archive.com/discussion%40acfug.org/ List hosted by http://www.fusionlink.com - - To unsubscribe from this list, manage your profile @ http://www.acfug.org?fa=login.edituserform For more info, see http://www.acfug.org/mailinglists Archive @ http://www.mail-archive.com/discussion%40acfug.org/ List hosted by http://www.fusionlink.com -