Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6168897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:45:58+00:00 2026-05-23T22:45:58+00:00

I believe there is a memory leak with the TypedFactoryInterceptor. Please consider the following

  • 0

I believe there is a memory leak with the TypedFactoryInterceptor.

Please consider the following scenario:

[Factory]
public interface IMyFactory 
{
     MySingleton GetInstance();
}

[Singleton]
public class MySingleton
{
}

[Singleton]
public class MyController
{
    public MyController(IMyFactory factory)
    {
        // using a for loop to simulate repeated calls to the factory instance over
        // a long time
        for(int i = 0; i < 100000; i++)
        {
            var instance = factory.GetInstance();
        }
    }
}

In the above example, the TypedFactoryInterceptor will contain a list of 100000 WeakReferences, all of which point to the same Target instance (of MySingleton). So, in the scenario where one singleton depends of a factory to create instances of another singleton, you can end up with hundreds of thousands of WeakReferences and thus a memory leak.

In doing some looking at the source code, it looks like the problem is here (in TypedFactoryInterceptor.Resolve):

// this is called on every Resolve call to the TypedFactory (IMyFactory.GetInstance)
if (this.kernel.ReleasePolicy.HasTrack(instance))
{
    // there will not be any dead references because MySingleton is a Singleton
    this.CollectDeadReferences();
    // adds another WeakReference to the same Singleton instance
    this.resolvedTrackedComponents.Add(new WeakReference(instance));
}

Any thoughts?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:45:59+00:00Added an answer on May 23, 2026 at 10:45 pm

    That is a result of the trick with WeakReferences being a workoaround for architectural limitations in Windsor 2.5 rather than a full blown solution.

    This is fixed in (upcoming) Windsor 3, where no WeakReferences are involved.

    As a temporary workaround I guess your best option is to not use a factory for that singleton (or upgrade to Windsor 3).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I believe there's a way to find the kth largest element in an unsorted
I believe there is a way to do this, but I'm not familiar with
There gotta be an easy way to do this, I can't believe there's none.
In the early days of .NET, I believe there was an attribute you could
Is Software Testing really given its importance at the academic level? I believe there
I found this solution which works, but I find it hard to believe there
Premise I believe that there is a way to objectively define "Good" and "Bad"
Although there are a lot of posts about .net config files, I believe that
In the UK throughout the 80's and 90's (70's too I believe!) there was
In the following two cases, if Customer is disposable (implementing IDisposable), I believe it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.