Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 153
  • Last Modified:

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..
0
Tacobell777
Asked:
Tacobell777
  • 6
  • 6
1 Solution
 
mosphatCommented:
Correct me if I'm wrong, but I believe it works like this: everything you create is a reference to an object. If you do application.complexvar = complexstruct, then application.complexvar is already a reference to complexstruct. Knowing this, you can easily work out the rest: server.complexvar = application.complexvar will give you another reference to complexstruct. And of course the object is destroyed only then, when the last reference is deleted.

HTH,
Ruud
0
 
Tacobell777Author Commented:
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..
0
 
mosphatCommented:
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? :)
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Tacobell777Author Commented:
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?
0
 
mosphatCommented:
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... :)
0
 
Tacobell777Author Commented:
I also posted this question to some forums, no definate answer there either ;-)

Ruud is toch echt een nederlandse naam (volgens mij?) ;-)
0
 
mosphatCommented:
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...

0
 
Tacobell777Author Commented:
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 :-((
0
 
pinaldaveCommented:
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
0
 
mosphatCommented:
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.
0
 
Tacobell777Author Commented:
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..
0
 
mosphatCommented:
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 :) )
0
 
Tacobell777Author Commented:
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..
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now