CSharpTest.Net
ObjectKeepAlive Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Utils Namespace : ObjectKeepAlive Class

Glossary Item Box

Provides a means of forcing the garbage collector to wait on objects aquired from permanent storage while only holding WeakReference's of the object. Essentially uses a simple lockless algorithm to track the most recently loaded objects so that they will stay alive longer.

Syntax

Visual Basic (Declaration) 
Public Class ObjectKeepAlive 
   Implements IObjectKeepAlive 
C# 
public class ObjectKeepAlive : IObjectKeepAlive  

Example

Library/Library.Test/TestObjectKeepAlive.cs

C#Copy Code
TimeSpan timeout = TimeSpan.FromMilliseconds(25);
ObjectKeepAlive keep = new ObjectKeepAlive(100, 10000, timeout);

for (int i = 0; i < 100000; i++)
    keep.Add(i);

System.Threading.Thread.Sleep(timeout);

for (int i = 0; i < 10000; i++)
    keep.Add(i);
VB.NETCopy Code
Dim timeout As TimeSpan = TimeSpan.FromMilliseconds(25)
Dim keep As New ObjectKeepAlive(100, 10000, timeout)

Dim i As Integer = 0
While i < 100000
    keep.Add(i)
    System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While

System.Threading.Thread.Sleep(timeout)

Dim i As Integer = 0
While i < 10000
    keep.Add(i)
    System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While

Inheritance Hierarchy

System.Object
   CSharpTest.Net.Utils.ObjectKeepAlive

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys