1

We are using OpenRasta for a service to serve up binary resources (images and PDFs mostly). Some of these are relatively large (5-75MB). We were encountering issues with performance, and, using the ANTS memory profiler, determined that there appeared to be memory leaks.

We have been using StructureMap for DI, and found the following modification in a blog post:

public void HandleIncomingRequestProcessed()
{
    HttpContextLifecycle.DisposeAndClearAll();
}

The leaks went away when we made a the further modification:

public void HandleIncomingRequestProcessed()
{
    HttpContextLifecycle.DisposeAndClearAll();
    ObjectFactory.EjectAllInstancesOf<IRequest>();
    ObjectFactory.EjectAllInstancesOf<IResponse>();
    ObjectFactory.EjectAllInstancesOf<ICommunicationContext>();
}

EDIT: This is not a good idea, as it will mess up concurrent requests. See the comments to the answer.

Essentially, I want to know, will this screw anything up? Or is it a pull request worth submitting?

Here are the before/after pics from the profiler:

Before

After

Thanks-

Dave Nichol
  • 181
  • 3
  • 8
  • Similar, but not identical, problem here: http://stackoverflow.com/questions/28299352/using-structuremap-unable-to-dispose-and-clear-references-to-a-dependency-setup – Iain Feb 03 '15 at 12:49

1 Answers1

1

Do a pull request. The SM support is poor and the context store is not in use, hence the problems you're seeing (amongst other problems that is).

That said, wouldn't evicting all instances of IRequest remove all the ones in the http context SM uses? You may want to check the documentation there.

SerialSeb
  • 6,701
  • 24
  • 28
  • We will look into it. I'll keep the question open a bit longer in case anyone has any other thoughts. Thanks! – Dave Nichol Apr 19 '12 at 14:05
  • Ok, so this ended up being a problem. I'm working on updating the SM DependencyResolver to use the context store, but my understanding of SM/OR internals is lacking! If I come up with something workable, I'll submit a pull request. – Dave Nichol Apr 20 '12 at 14:06
  • You might want to have a look at this fork: https://github.com/7digital/openrasta-stable/tree/master/src/structuremap/OpenRasta.DI.StructureMap – grahamrhay May 09 '12 at 08:06
  • Dave Can you run the profile on this copy of the code and see if it fixes it? We *think* it does but we're not 100% sure as it was fairly intermittent https://github.com/openrasta/openrasta-structuremap/pull/3 Thanks. – Antony Denyer Jun 13 '12 at 09:44