views:

56

answers:

1

Hi,

i want to add an existing object to my unity container registered to a specific interface,

so when i resolve the interface i get that existing object (it's used for testing, and the object holds a lot of XML data, and for eacht test case i want to use another object).

I do it like this:

public static void RegisterInstance<T>(T instance)
        {

            container.RegisterInstance<T>(instance);
        }

where container is my UnityContainer. This code is in a static class called IoCContainer

My call then is:

IoCContainer.RegisterInstance<IConfigurationRepository>(new MockConfigurationRepository(XML));

this seems to work, but when i later add a new instance, the old one seems to held in memory by Unity. So when i later on want to register object B in stead of object B (during testing) and later on register C , unity correctly resolves C but it keeps B and A in memory (and they are quite large, that't why i noticed.

Is there a way to remove A and B from Unity's memory?

A: 

Well, what seems to be the problem is not that Unity holds the object, but an object created in the app, which uses the object, is keeping the GC from collecting it.

So this not realy an answer, but i didn't see any delete button for my question....

Michel