Garbage Collection is an integral part of the .NET Framework world. The .NET's garbage collector (GC) manages the allocation and release of memory for your applications. Garbage collection in Telerik Data Access is extremely important because of the number of potential references in the first level cache.
Telerik Data Access allows you to configure the type of the references maintained by the cache of the OpenAccessContext. There are three possible modes:
- Strong - specifies that all references can't be reclaimed.
- Weak - specifies that a reference is maintained using a System.WeakReference allowing the garbage collector to reclaim the object.
- Auto - specifies that references to fetched data are strongly held and references to user instances are weakly held. When data is fetched from the server (or the second level cache), it is put into state objects. These state objects are then put (or updated in) the first level cache. The first level cache will reference the state instances with a string reference, until the persistent object (that the state holds the values for) is generated. Then the first level cache strong reference is updated to a weak reference as the user application is now responsible to hold the reference to the object. In this way, fetched data is not lost due to GC activities, but the data can be eventually garbage collected when the application has lost the reference to that data.
The default cache reference type behavior is Auto.
In order to configure the cache reference type behavior by using the Model Settings Editor:
- Open your domain model in the Visual Designer.
- Right-click on an empty area and select Show Model Settings.
- In the Model Settings Dialog navigate to the Backend Settings -> Runtime Configuration tab page.
Modify the Cache Reference Type option.
The second way for configuring the cache reference type is to use the BackendConfiguration class. To do this use the CustomizeBackendConfiguration partial method by implementing it in a separate code file for your partial context class. Modify the cache reference type in the following manner:
public partial class EntitiesModel
static partial void CustomizeBackendConfiguration(ref BackendConfiguration config)
config.Runtime.CacheReferenceType = CacheReferenceType.Weak;
Partial Public Class EntitiesModel
Private Shared Sub CustomizeBackendConfiguration(ByRef config As BackendConfiguration)
config.Runtime.CacheReferenceType = CacheReferenceType.Weak