How does Httphandler reusable memory work?

I created HttpHandler and follow the setup in Web.config

<add verb="*" path="*.png" type="MvcApplication1.Handler2"/> IsReusable = true in HttHandler 

Say I have 20 users in my application who are trying to enter the following url

 http://Domainname/abc.jpg 

As we all know, if IsReusable = false . Upon completion of the response, the HandlerRecycleList HttpApplication will set to null, but this is not the case with the following

 IsReusable = true 

Question

  • Will the HttpHandler memory be shared with all users if IsReusable = true ?
  • or let's say I requested the above URL and that memory will only be allocated to me, and next time it will be reused in my case, and session-based HttpHandler memory will be allocated to other users?
+4
source share
1 answer

Yes, the handler is common to all users. It is not tied to any session object.

If you set Reuse to true, the instance will be cached and reused in other requests, simply repeating its ProcessRequest method again and again, without creating new instances. The handler does not look at the session for this. The application will create as many handlers as necessary to handle the current load.

So, if you have 20 users at the same time as your application, 20 instances will be created. If, on the other hand, you have 20 users accessing your handler sequentially, only one instance (re) will be used.

You cannot control the number of created instances; this is done on demand.

The downside is that if you use most of the memory in the handler, it will negatively affect memory usage, as these instances will survive GC loops.

You must also ensure that the state at the end of the processRequest is valid for the next request.

+3
source

Source: https://habr.com/ru/post/1482504/


All Articles