You can't use Castle Core 4.0.0 with Windsor as there is no version of
Windsor that currently supports Castle Core 4.0.0.

On Tue, Feb 21, 2017 at 11:47 PM erazem <zupan....@gmail.com> wrote:

> Application is calling Release after each Resolve(). Only dispose on any
> controller is not called.
>
> I have updated the library to 4.0.0.0. but get the following error:
> *Attempt by method
> 'Castle.MicroKernel.SubSystems.Configuration.DefaultConfigurationStore..ctor()'
> to access method
> 'System.Collections.Generic.Dictionary`2<System.__Canon,System.__Canon>..ctor()'
> failed.*
>
> public WindsorControllerFactory()
> Line 26:         {Line 27:             container = new WindsorContainer()Line 
> 28:                 .Install(FromAssembly.This())
> Line 29:                 .AddFacility<WcfFacility>();
>
>
> Any idea?
>
> I will look for interceptors you have send.
>
> thanks
>
> On Tuesday, 21 February 2017 14:12:33 UTC+1, Jonathon Rossi wrote:
>
> I don't have the time to really look through all the screenshots to try to
> guess what is going on, but I was surprised to see so many instances of the
> controllers living. Can you confirm that your application is calling
> Release() since it is explicitly calling Resolve(). I'm not sure it'll
> solve the problem though as you said without the add logging call you don't
> get the memory leak.
>
> Here are the pages in Windsor's docs that talk about setting up
> interceptors that'll automatically be configured when you resolve a
> component, best to use the fluent registration API:
> https://github.com/castleproject/Windsor/blob/master/docs/interceptors.md
>
> https://github.com/castleproject/Windsor/blob/master/docs/registering-interceptors-and-proxyoptions.md
>
> On Tue, Feb 21, 2017 at 8:23 PM erazem <zupa...@gmail.com> wrote:
>
> Maybe this print screen is also of some help:
>
>
> <https://lh3.googleusercontent.com/-ITgBAFHN6fE/WKwU9P0pCMI/AAAAAAAAC7c/clhE7xfJPTcFn_QAF8fenCKnviJJWw5EgCLcB/s1600/profiling3.JPG>
>
>
> On Tuesday, 21 February 2017 10:58:58 UTC+1, erazem wrote:
>
> I will try with new version and let you know.
>
> I have opened dotMemory profiling and this is the result:
>
>
> <https://lh3.googleusercontent.com/-Bb4Jwgnr-6U/WKwNO8IU7EI/AAAAAAAAC7A/yNCWE54uql4TmVKtm1LivRvcL_Dogb7pQCLcB/s1600/profiling0.JPG>
>
>
>
> It shows that there some system collections and reflection increasing?
>
> But If i open second snapshot and go to Largest retained Size I can see
> that Castle kernel is the one with most bytes:
>
>
> <https://lh3.googleusercontent.com/-v5gR6VQOtPk/WKwMY24dckI/AAAAAAAAC60/tZP2exBfPzk0MEUCCK-imWE8PfZyTIC7gCLcB/s1600/profiling1.JPG>
>
> If I go further, I can see this:
>
>
>
> <https://lh3.googleusercontent.com/-j0Xw2rwgUSg/WKwNg4CBUbI/AAAAAAAAC7I/CVhthoVf7YQHW_eJZEc7Kemg0bhAid_kwCLcB/s1600/profiling2.JPG>
>
> Can you see from this where is the problem?
>
> The interceptor log start and end time for each controller method if trace
> is enabled in web config - that is all.
>
> sbTraceMethod = GetControllerActionName(invocation);
> logger.TraceFormat("Entering {0}", sbTraceMethod);
>
> *ticksBefore = DateTime.Now.Ticks;*
> *invocation.Proceed();*
> *ticksAfter = DateTime.Now.Ticks;*
> *success = true;*
> *logger.TraceFormat("Leaving {0} with success: {1} elapsed time: {2}ms",
> sbTraceMethod ?? "[no info]", success, TimeSpan.FromTicks(ticksAfter -
> ticksBefore).TotalMilliseconds);*
>
> I don't know the reason for dynamic proxy - it is not my code. I'm not
> that familiar with Castle, I have to read documentation.
> I could use Windsor's functionality to set up an interceptor when resolve
> a controller. Do you have some example?
>
>
> On Tuesday, 21 February 2017 05:57:14 UTC+1, Jonathon Rossi wrote:
>
> You'll get a different proxy type per interface, however it looks like
> your code is creating all proxies with the same IController interface. I
> can't remember what Castle Core 3.3.3 does with AdditionalAttributes
> whether it looks at them in the caching code since you are attaching
> different attributes based on controller implementation type, this is where
> we had a defect in 3.3.3 which was only half fixed in 4.0.0-alpha001 before
> being properly fixed in 4.0.0-beta002.
>
> Apologies for not making my request clearer but "w3wp.exe memory goes up
> to 99% of server memory in couple of hours" isn't very useful to narrow
> things down, knowing where the memory has gone is what is more useful, i.e.
> is it leaking controllers or dynamic proxy types or something else,
> something like dotTrace would be the best tool but there are many other
> options.
>
> Just taking a step backwards is there a reason you aren't using Windsor's
> functionality to set up an interceptor when you resolve a controller?
>
> On Tue, Feb 21, 2017 at 2:01 AM erazem <zupa...@gmail.com> wrote:
>
> I have just found out that type, which "CreateInterfaceProxyWithTarget"
> method return is different. It is:
>
> Castle.Proxies.IControllerProxy_1
> Castle.Proxies.IControllerProxy_2
> Castle.Proxies.IControllerProxy_3
>
> and so on....
> But each type is returned randomly more than once.
>
> Is this a reason for memory leak? Why it returns different types? Is it
> because there are different controllers?
>
>
> On Monday, 20 February 2017 16:13:25 UTC+1, Jonathon Rossi wrote:
>
> Apologies for not coming back to your StackOverflow question (
> http://stackoverflow.com/questions/42272082/castle-windsor-proxy-generate-memory-leak)
> after you added the code for "AddControllerLoggingFunctionality".
>
> Can you further explain what you mean by a memory leak, i.e. what exactly
> is leaking? The first thing I'd check is what proxy type is being returned
> by CreateInterfaceProxyWithTarget, i.e. is it the same type each time or is
> DynamicProxy generating a new type each time and therefore bloating its
> unclearable type cache. Since you are using ProxyGenerationOptions
> especially with AdditionalAttributes this is an area we've had a defect and
> some changes recently (
> https://github.com/castleproject/Core/blob/master/CHANGELOG.md), do you
> still get the memory leak if you comment out the line with
> "options.AdditionalAttributes.Add(...)". What version are you using?
>
> https://github.com/castleproject/Core/issues/77
> https://github.com/castleproject/Core/pull/78 (4.0.0-alpha001)
> https://github.com/castleproject/Core/pull/219 (4.0.0-beta002)
>
> P.S. you should use the Stopwatch class which uses the very quick high
> precision query performance timer rather than DateTime.Now.
>
> On Tue, Feb 21, 2017 at 12:23 AM erazem <zupa...@gmail.com> wrote:
>
> In my MVC application there is Castle Windsor used as it is described here:
>
> https://github.com/castleproject/Windsor/blob/master/docs/mvc-tutorial-part-2-plugging-windsor-in.md
>
> When "container.Kernel.ReleaseComponent(controller)" is called, this
> controller is not disposed and remains in memory forever - it introduce
> memory leak.
> The reason for this must be:
>
> There is only one difference, when you get a controller instance, there is
> called extension method, which adds some login functionality to controller:
>
>        *protected override IController
> GetControllerInstance(RequestContext requestContext, Type controllerType)*
> *        {*
> *            if (controllerType == null)*
> *            {*
> *                throw new HttpException(404,*
> *                    $"The controller for path
> '{requestContext.HttpContext.Request.Path}' could not be found.");*
>
>
> *            }*
>
> *           return
> ((IController)container.Kernel.Resolve(controllerType)).AddControllerLoggingFunctionality();
>          // if it is without extension methos, there is no memory leak:*
>
> *           //return
> (IController)container.Kernel.Resolve(controllerType);*
> *        }*
>
> The controller instance looks like this:
>
>
> <https://lh3.googleusercontent.com/-caNhjJ3C8Uc/WKr7UycBBaI/AAAAAAAAC6Q/T-pMPEje3NkSlz29whUja5nQeYZklYOiwCLcB/s1600/controller.JPG>
>
> So, AddControllerLoggingFunctionality is responsible for memory leak.
> This method is inside Logger class and use Castle DynamicProxy interceptor:
>
>  *public static class Logger*
> * {*
> *        private static readonly Castle.DynamicProxy.ProxyGenerator
> proxyGenerator;*
>
> *        static Logger()*
> *        {*
> *            proxyGenerator = new Castle.DynamicProxy.ProxyGenerator();*
> *
> Castle.DynamicProxy.Generators.AttributesToAvoidReplicating.Add(typeof(ServiceContractAttribute));*
> *        }*
>
> *       public static TInterface
> AddControllerLoggingFunctionality<TInterface>(this TInterface
> implementation) where TInterface : class*
> *        {*
> *            if (implementation == null)*
> *            {*
> *                throw new ArgumentNullException("implementation");*
> *            }*
>
> *            if (!typeof(TInterface).IsInterface)*
> *            {*
> *                throw new Exception("Type of 'TInterface' must be
> interface.");*
> *            }*
>
> *            Castle.DynamicProxy.ProxyGenerationOptions options = new
> Castle.DynamicProxy.ProxyGenerationOptions();*
>
> *            var origAttribs =
> implementation.GetType().GetCustomAttributesData();*
> *            if (origAttribs != null)*
> *            {*
> *                foreach (var origAttrib in origAttribs)*
> *                {*
> *
> options.AdditionalAttributes.Add(AttributeUtil.CreateBuilder(origAttrib));*
> *                }*
> *            }*
>
> *            return
> (TInterface)proxyGenerator.CreateInterfaceProxyWithTarget<TInterface>(*
> *                implementation,*
> *                options,*
> *                new
> ControllerLoggingInterceptor(implementation.GetType()));*
> *        }*
>
> *       private class ControllerLoggingInterceptor :
> Castle.DynamicProxy.IInterceptor*
> *        {*
> *            private readonly Type typeTarget = null;*
> *            private readonly ILog logger = null;*
>
> *            public ControllerLoggingInterceptor(Type type)*
> *            {*
> *                this.typeTarget = type;*
> *                this.logger = LogManager.GetLogger(this.typeTarget);*
> *            }*
>
> *            public ControllerLoggingInterceptor()*
> *            {*
> *                this.logger =
> LogManager.GetLogger("NullTargetAutoLogger");*
> *            }*
>
> *            public void Intercept(Castle.DynamicProxy.IInvocation
> invocation)*
> *            {*
> *                bool success = false;*
> *                string sbTraceMethod = null;*
> *                long ticksBefore = 0;*
> *                long ticksAfter = 0;*
>
> *                try*
> *                {*
> *                    if ((this.logger != null) &&
> this.logger.Logger.IsEnabledFor(log4net.Core.Level.Trace))*
> *                    {*
> *                        sbTraceMethod =
> GetControllerActionName(invocation);*
> *                        logger.TraceFormat("Entering {0}",
> sbTraceMethod);*
> *                    }*
>
> *                    ticksBefore = DateTime.Now.Ticks;*
> *                    invocation.Proceed();*
> *                    ticksAfter = DateTime.Now.Ticks;*
> *                    success = true;*
> *                }*
> *                catch (Exception)*
> *                {*
> *                    ticksAfter = DateTime.Now.Ticks;*
> *                    success = false;*
> *                    throw;*
> *                }*
> *                finally*
> *                {*
> *                    if (this.logger != null*
> *                     &&
> this.logger.Logger.IsEnabledFor(log4net.Core.Level.Trace))*
> *                    {*
> *                        logger.TraceFormat("Leaving {0} with success: {1}
> elapsed time: {2}ms", sbTraceMethod ?? "[no info]", success,
> TimeSpan.FromTicks(ticksAfter - ticksBefore).TotalMilliseconds);*
> *                    }*
> *                }*
> *            }*
>
> *            private static string
> GetControllerActionName(Castle.DynamicProxy.IInvocation invocation)*
> *            {*
> *                ParameterInfo[] methodParams =
> invocation.Method.GetParameters();*
> *                ParameterInfo activityParameterInfo =
> methodParams.FirstOrDefault(x =>*
> *
> x.ParameterType.Equals(typeof(System.Web.Routing.RequestContext)));*
>
> *                if (invocation != null && invocation.Arguments != null)*
> *                {*
> *                    System.Web.Routing.RequestContext rq =
> invocation.Arguments[activityParameterInfo.Position] as
> System.Web.Routing.RequestContext;*
>
> *                    if (rq != null && rq.RouteData != null &&
> rq.RouteData.Values.Count >= 2)*
> *                    {*
> *                        return String.Format(*
> *                            "{0}.{1}()",*
> *                            rq.RouteData.Values["controller"],*
> *                            rq.RouteData.Values["action"]);*
> *                    }*
> *                }*
> *                return "UNKNOWN";*
> *            }*
> *        }*
> *}*
> The controller object is like this:
>
> What should I change to avoid memory leak and keep functionality as it is?
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to castle-project-users+unsubscr...@googlegroups.com.
>
> To post to this group, send email to castle-pro...@googlegroups.com.
>
>
> Visit this group at https://groups.google.com/group/castle-project-users.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to castle-project-users+unsubscr...@googlegroups.com.
> To post to this group, send email to castle-pro...@googlegroups.com.
> Visit this group at https://groups.google.com/group/castle-project-users.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to castle-project-users+unsubscr...@googlegroups.com.
> To post to this group, send email to castle-pro...@googlegroups.com.
> Visit this group at https://groups.google.com/group/castle-project-users.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to castle-project-users+unsubscr...@googlegroups.com.
> To post to this group, send email to castle-project-users@googlegroups.com
> .
> Visit this group at https://groups.google.com/group/castle-project-users.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to castle-project-users+unsubscr...@googlegroups.com.
To post to this group, send email to castle-project-users@googlegroups.com.
Visit this group at https://groups.google.com/group/castle-project-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to