Re: About speed



Ingvar Nilsen wrote:
In fact, using "using" requires the object in question to support
IDisposable.

I am wondering if the system at all calls Dispose()? Does the GB call
Dispose()? Most likely.. Easy to test, shall I?


Most IDisposables have a finalizer, that will call Dispose when the object is marked on a GC sweep. But those IDisposables will most likely call GC.SupressFinalizer inside their Dispose method. Thus using "using" will prevent finalizers from being executed. Finalizers can slow things extremely down, because they to be synchronized as the GC runs in its own thread.

>
> And you are right. There is no way to free objects the Delphi way as
> far as I know.
>

It is possible, but I won't explain how. Last time I did, I had to explain that someone why he shoot himself in the foot. You only need it, if your design is fundamentally flawed. But then, you'd have to redesign anyway. ;-)
A not-as-nasty-but-still-flawed solution would be to call GC.Collect twice. Thus every non-collected object will be gen 1 after the first collect and since it wasn't touched between the 1st and the 2nd, it will be free'd after the 2nd Collect.
This *could* be necessary if you won't leave enough resources for the GC Thread to do its job. In a standard user-mode application, GC will run in a Background thread. Thus if you do a lot of crunching, GC will sweep only if you've eaten *lots* of memory.
.



Relevant Pages

  • Paradigm for multiple IDisposables
    ... a list of IDisposables inside the using statement, ... Write a new class (MultiDispose), ... MultiDispose.Dispose, run through the list and Disposeeach item in ... using (Disposable2 Second = new Disposable2()) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Paradigm for multiple IDisposables
    ... you and call IDisposable in the face of exceptions. ... IDisposable on MultiDispose, you have to wrap the call to Dispose on each ... a list of IDisposables inside the using statement, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: IDisposable or not in custom classes
    ... Clean Up Unmanaged Resources" ... ".NET Framework Developer's Guide, Implementing a Dispose Method" ... Note that the guidelines recommending to use Dispose along with a finalizer ... references to IDisposables since each IDisposable reference should have ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problem with C# not calling MC++ destrcutor
    ... You should deal with other resources using the dispose pattern in C#. ... At the next garbage collection they will be placed in the queue of object to be finalized, and a background process will call their finalizers eventually. ... If you implement IDisposable, it will make the memory management much more efficient. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: garbage collection of open resources
    ... > It does, there's just no guarantee. ... If finalizers take too long or create ... not calling Dispose() on a disposable object is a bug in the ... I just wanted to point out that resource leakage ...
    (microsoft.public.dotnet.languages.csharp)