Click here to Skip to main content
15,887,992 members

Comments by adamvanner (Top 6 by date)

adamvanner 17-Jan-11 12:35pm View    
oh and by the way, irony of all ironies... and youre in some way entitled to go into smug mode here.. the node I deleted did eventually get collected,.. but it seems to take between 5 and 15 minutes!! Ive never even realised objects would linger that long. maybe the extra 4 Gb of memory makes the GC less quick off the mark?

Im glad that shows avRef is working properly, but I'm still going to finish off the scene traversal function as it could well come in handy. Will post as an article once done.
adamvanner 16-Jan-11 23:56pm View    
To give you a full idea of the project and the effect that is occurring:

The program Im working on has a script interface as well as a Node/ OpenGL 3D view based GUI. Im testing fail conditions within scripts. So the user enters a script which encounters an exception some way through. The script has run some way through and I must undo the parts of the script which it ran successfully, and flush the undo queue.

The complexities stem from the fact that when an object is created, it informs subscribers to global events (such as editors and 3Dviews) that they should show it/draw it etc. Now some time later in the script, an exception occurs and a second event must be called to say the same object must be deleted. All registered editors, the undo queue, and the scene graph show the object to be successfully removed, but even if I wait 10 minutes, when I check the weak reference, its target still points to the lingering, deleted and disposed object, so something is still pointing to it. If I wanted to, I could ignore it. It makes apparently no difference... but it should have been collected so something isnt being used the way it should be and so all I want to be able to establish is what reference is keeping it lingering.. I dont want to GC the object, but its important for me to find out why it isnt being GC'd. Make more sense now?
Again, I'd just point you back to the title of my question!

unless youve heard of an unreferenced object not being collected after 10 minutes? Could that happen?
adamvanner 16-Jan-11 23:44pm View    
Again, perhaps Im being sloppy and youre picking up, rightly, on my semantics..

the point I was making about the spotlight is that it is no longer needed as soon as that snippet leaves scope.. whether GC happens immediately or later is of no concern,.. it should happen because the object isnt needed.

Just so were on the same page and you know I know about GC... ;)

GC occurs when there are no more references to a heap object. When? could be 1000's of times a second, could be much later. More often than not we dont know or care (unless dealing with native resources) The GC thread checks for unreferenced heap objects (not using old VB style ref counting which encounters lost "pairs" of self refed objects) When using "using" with an IDisposable object, the dispose method is called at the end of the scope. The remaining memory may be collected, or as far as I understand it, be reused if called frequently. As you so rightly say, we should not know or care,.. thats the point of GC, to take away the owness of memory management from the programmer... and .net does a very good job of it too!

Ive been coding in C# for 6 years now, so Im really genuinely not confused by GC in any way!

The point is not that Ive lost a ref to an object (as you say, we dont care when that happens). The point is that the WeakReference has shown me that there is still at least one reference in my code, somewhere. Possibly in the containers, (although since the ones ive checked are verified null, the rest should all work as they are all treated the same)... but thats why Im writing this code.. to check!! thats all!
adamvanner 16-Jan-11 23:24pm View    
lol sorry perhaps Im making this more confusing than it needs to be! I mentioned Dispose() there ONLY to say that this isnt to do with freeing resources etc!
Lets say the user has selected a light and deleted it. I disconnect everything, call the Dispose() (reason: developers can write plugins to extend these types, so feasibly there could be some native data which needs to be freed, for example, the code uses OpenGL so its critical that clients have the opportunity to free unmanaged resources in a strict order.

Basically after the object is deleted, it should be disconnected from the world. Think of this as a "side effect of the system" more than goal of the system. This genuinely ISNT about memory management, moreover reference management.

adamvanner 16-Jan-11 22:55pm View    
yes, thanks.. to be fair I only ran this once on a very simple case knowing full well that it wont work when searching through most commonly field / property types such as arrays & collections, generics, indexers etc. The combinations start to become pretty horrendous! Still Im working through them, but it will definitely take a fair dev time to enable it to be able to graph every facet of a program! Maybe a week of PT coding :/