Link to home
Start Free TrialLog in
Avatar of Tacobell777
Tacobell777

asked on

Reference stored in Server scope does not get deleted

When I create a reference to a complex structure I was always under the impression that the reference would be destroyed if the original is destroyed, but it seems this is not the case. Can anyone confirm whether this is normal behaviour or not?

What I am trying to do is set a complex var in the application scope, create a reference to it in the server scope and was hoping it would get destroyed when the application times out, but its not working, unfortunately..
ASKER CERTIFIED SOLUTION
Avatar of mosphat
mosphat

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tacobell777
Tacobell777

ASKER

not everything is a reference, only complex objects (I believe), whatever the case, you are repeating what I already said.
The problem is that the reference does not get destroyed while the original object in the application is...

Groetjes..
Hoi Taco,

You're right in that not everything is a reference. I was refering to complex objects (structs, array, cfc's, queries), just forgot to actually write that...

As for me repeating you: I didn't. I just tried to make clear that <cfset application.somevar = structNew()> already is a reference. The original in this case is structNew(), not application.somevar. There is in this case no way (that I know of) to destroy the original. It's only possible to destroy each and every reference. (Removing the last reference will also remove the original of course)

So when you create a complex object...

<cfapplication name="test" sessionmanagement="Yes">
<cfset application.test = structNew()>
<cfset application.test.blabla = "ingewikkelde structure">

... application.test is merely a reference to it.

<cfset session.test = application.test>

... now session.test is another reference to it.

<cfset structdelete(application, "test")>

... deleting the first reference, but keeping the object, since there's still a reference remaining as is proved by:

<cfdump var="#session#" />
<cfdump var="#application#" />

Snappie? :)
Exactly, and that is the whole problem I am having...

If you update the original object then the reference is *also* updated, but when you delete the original object you would expect the reference to be deleted as well, wouldn't you??

My questions is:
is this normal behaviour, yes or no?

Snapu ?
Niet verbaast hoe ik weet dat je nederlands bent?
You can't delete the original (complex) object directly.

What you are deleting is the first reference you made to it. And as long as there are other references to it, the object will remain intact.
In <cfset application.somevar = structNew()> the object is not application.somevar, it is structNew(). Therefore, if you delete application.somevar, you're deleting a reference. But I think that is clear now. We just have different ways of describing the issue.

Is is normal behaviour? I think it is. What you're really asking is: should there be a way to delete/access the original directly (rather than the first refence to it)? Maybe. I'm not sure whether it would violate some computer law or not. It would surely solve your problem. However, I'm not sure whether it should be solved that way in the first place.
I know, it's no definitve answer yet, but it's still early...

> Niet verbaast hoe ik weet dat je nederlands bent?
Iets zegt me dat je daar niet op gekomen bent vanwege m'n naam. In dit geval begin ik het me wel af te vragen... :)
I also posted this question to some forums, no definate answer there either ;-)

Ruud is toch echt een nederlandse naam (volgens mij?) ;-)
Bij mijn weten ook. :) Heb m'n profiel er ook maar ff op aangepast.

Have you tried your question with the people who build ColdFusion? Surely they have an answer...

And the answer is..........

The object exists as long as a reference to it exists, so its normal behaviour, and I can't do what I wanted to do :-((
Avatar of pinaldave
Hi ee_ai_construct,
The answer from TacoBell is good one. I never knew this and learnt from this thread.
I will suggest PAQ/Refund.

Regards,
---Pinal
Hmm, what about my efforts to explain WHY TacoBell's problem occurs? Surely, it does not solve the situation, but then again, you don't have a garantuee that someone does provide a solution.

Besides, he never told what he wanted to achieve, using this technique. Therefore leaving us no chance to provide an alternative.

And I was still looking into this question, so you might not want to close this question to soon.
Mosphat, no offense, I did explain what I wanted:

"What I am trying to do is set a complex var in the application scope, create a reference to it in the server scope and was hoping it would get destroyed when the application times out, but its not working, unfortunately.."

What you explained to me I already knew, the only question was why a reference is updated but not deleted when one or the object is destroyed...

But if you really wants the points you can have them..
Taco, no offense taken :)

You explained you wanted the reference in the server scope to be destroyed when the original object is destroyed. But what is it that you need to have these references in the server scope for in the first place? Maybe if you describe the larger picture, we can find a possible alternative solution there.

As for explaining what you already know: you've found out that the reference is not deleted, when you delete the object. But what I tried to explain is: you can't really delete the object, since you only have access to it through references. If you do structDelete(application, "complexStruct") or even if the application scope times out, you're not deleting the object, it's just the reference that's being destroyed. The object itself still resides in memory somewhere, because the server-reference keeps pointing to it. Once that's gone too, the object is destroyed.

The points are only of interest to me, if my answer(s) helped you gain more insight. If not, I'd like to know why not (and probably try again :) )
ok, so you want to know the "why" behind all this.
The why is:
I have some settings in the server scope that I want destroyed when the application times out, as for another solution for that, I already knew of one before I aksed this question, I just wanted to see why my first idea was not possible. (the other solution is writing a javasclass as a listener)

When I read some of my posts I see that my wording is a bit wrong, which might have confused you.

Lets assign some points as what you are saying is part of the answer..