>It is totally new for me that the created object are distroying automatically after going out of scope

In general, scope has nothting to do with when GC decides to release an object (although static analysis of scope and lifetime can be used as an optimization) -- objects are automatically released when there are no longer any references to them. The general rule of thumb is to just let the garbage collector do it's job and not worry about it. (In very rare cases you can look at things like weak references if you need them.)

> Is there any way to destroy and release a class object that was created by NEW keyword in order to reuse the NEW (perhaps with different input parameters)?

You should never need to do this and in general there is no way to "force" a .Net object to be returned to the free pool - this would be a very bad idea, as the system is a much better judge of this than the programmer is, and would introduce a flavor of bug that we don't have now.

>. Using VisualStudio 2010 can I create a class object delayed from member function that can be used by any other member function? The delayed creation would be very important, because at the declaration time the input parameters for the constructor are not yet available.

Can you clarify what you're asking with an example? Again, in general don't worry about object lifetime :)

If an object maintains references to external (files, etc.) or unmanaged memory resources, you can use the Dispose pattern (and use the using keyword in C# or F#) - this does rely on scope so that resources are relased as soon as possible, rather than waiting (possibly a long time) for the finalizer to be run. (But if you're sharing <i>external <i>resources among many connected objects with disconnected lifetimes, you probably don't want to use the scope-based <b>using </b>block, just use the finalizer.) I'd guess most F# programmers come from the .Net world or the functional world - coming straight from C++ and having this be your first managed/GC language, you may need to learn to "let go" or your urge to control object lifetime and revel in all the spare cycles you have to work on the actual problem at hand -- though there are some patterns to learn when dealing with non-managed resrouces. >Is there any way to transmit input parameter to a thread There are many ways to do this depending on what you mean -- you can start the thread with arguments (manually or using data-parallel constructs), you can used shared/global variables, DCOM, shared syncronized datastructures, F# mailboxes, sending messages via many channels (PostMessage, sockets, WCF, etc.) - depends what your goal is.

By on 12/21/2010 11:01 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper