Bug in cache prune?

23 views
Skip to first unread message

Remo Gloor

unread,
Apr 2, 2010, 4:18:15 PM4/2/10
to ninject
Hi,

We currently have the problem that cache prune stops after some time
which leads to memory leaks. It seems that the problem starts after
some idle time. I did some investigation and it seems that there is a
bug in
GarbageCollectionCachePruner.PruneCacheIfGarbageCollectorHasRun. Here
is the original source of this method:

private void PruneCacheIfGarbageCollectorHasRun(object state)
{
if (_indicator.IsAlive) return;

Cache.Prune();
_indicator.Target = new object();

_timer.Change(GetTimeoutInMilliseconds(), Timeout.Infinite);
}

If I understand it correct, the idea of the first line is to skip one
execution of cache prune if the garbage collector has not run since
the last execution. But what it actually does is stop cache prune
forever. So I think the implementation shoud rather be the following:

private void PruneCacheIfGarbageCollectorHasRun(object state)
{
try
{
if (_indicator.IsAlive) return;

Cache.Prune();
_indicator.Target = new object();
}
finally
{
_timer.Change(GetTimeoutInMilliseconds(), Timeout.Infinite);
}
}

What do you think about this? Does anyone know the idea behind this
first line of the method? Has anyone else the problem that cache prune
stops after some time too?

Ian Davis

unread,
Apr 2, 2010, 4:21:45 PM4/2/10
to nin...@googlegroups.com
If I understand correctly, your fix would handle the situation where Cache.Prune() throws an error. Are you seeing this behavior in your code?

Thanks,

-Ian


--
You received this message because you are subscribed to the Google Groups "ninject" group.
To post to this group, send email to nin...@googlegroups.com.
To unsubscribe from this group, send email to ninject+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ninject?hl=en.


Urs Enzler

unread,
Apr 2, 2010, 4:43:16 PM4/2/10
to ninject
The timer is not reset if

if (_indicator.IsAlive) return;

is taken.

If the GC did not run, then the timer is not reset and the cahce is
never pruned.

Cheers,
Urs

On Apr 2, 9:21 pm, Ian Davis <ida...@innovatian.com> wrote:
> If I understand correctly, your fix would handle the situation where
> Cache.Prune() throws an error. Are you seeing this behavior in your code?
>
> Thanks,
>
> -Ian
>

> > ninject+u...@googlegroups.com<ninject%2Bunsu...@googlegroups.com>

Ian Davis

unread,
Apr 2, 2010, 5:02:50 PM4/2/10
to nin...@googlegroups.com
Sorry, I misread the code. I think you are correct. Since the timer is set up without recurrence, if we don't set a new start and due time it won't trigger again.

-Ian

To unsubscribe from this group, send email to ninject+u...@googlegroups.com.

Ian Davis

unread,
Apr 2, 2010, 6:25:53 PM4/2/10
to nin...@googlegroups.com
I have confirmed the bug and the fix. I will push when I get a chance tonight. Nice find.

-Ian

Urs Enzler

unread,
Apr 3, 2010, 4:31:08 AM4/3/10
to ninject
Thanks Ian!

Keep up the good work.

Cheers,
Urs

On Apr 3, 12:25 am, Ian Davis <ida...@innovatian.com> wrote:
> I have confirmed the bug and the fix. I will push when I get a chance
> tonight. Nice find.
>
> -Ian
>

> > ninject+u...@googlegroups.com<ninject%2Bunsu...@googlegroups.com>

Reply all
Reply to author
Forward
0 new messages