Question

When you create an instance of the cachefactory and then don’t use it anymore the memory that was used during the creation of the object is not released. This will have a substantial effect on all web apps or scenarios where a cachfactory might be created multiple times. The symptoms of this will be unusually high memory use one the process and in IIS this will most likely result in your app having to recycle more often since it with overrun its allocated memory more quickly.

The following code will show an increase of about 500MB yes I mean MegaBytes of memory usage!

To duplicate put the following code into your app:

Dim CacheFactory1 As CacheFactory = New CacheFactory()
For i As Int32 = 1 To 1 * (10 ^ 4)
    CacheFactory1 = New CacheFactory()
    CacheFactory1 = Nothing
Next

There are only two workarounds for this.

  1. Velocity team fixes the bug (and I’m sure they will)
  2. You need to use the same cachefactory object on a static method in your app and reference it every time you want to use the cache. (this works but isn’t optimal in my opinion.)

I also have a cachingscope that can be used to wrap your caching methods and will post this on codeplex soon. You can wrap it around your caching methods just like a transaction scope and it will manage the locking and connection for you.

Was it helpful?

Solution 2

I've build a scope provider for resolving this issue. You can get the code here.

http://www.codeplex.com/CacheScope

OTHER TIPS

So where is the question? You should file the bug, and not post this here, as the Velocity team is more than likely monitoring Microsoft Connect for bugs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top