I am wondering what happens under the hood when a DropZoneJs instance is disabled with the .disable() or the .destroy() method, and that a new instance of DropZoneJs with the same name and jQuery selector is then created later :
Does DropZoneJs implicitely reuses the same instance, as if I was re-enabling it explicitely using the .enable() method ?
Does DropZoneJs creates a new instance ?
My tests show that DropZoneJs creates a new instance.
So if you continually create a Dropzone instance with a name, disable it using the .disable() method, then renew the operation 10 times, this will lead the number of Dropzones objects to be 10, not 1 :-(
This can be monitored by examining the Dropzone.instances.length property.
This is not good for memory management. So if possible, try to re-hydrate a disabled Dropzone instance by using the .enable() method if you know its name.
I achieved that by storing the Dropzone instance in a JS variable.
Related
I am using Prism to navigate between views in my WPF application. One view in particular I've implemented with the IRegionMemberLifetime.KeepAlive => returns false; to create a new instance of the view every time we navigate to the view (we need to do this for display reasons). This view also hosts a custom win32 control that I need to do some cleanup in using IDisposable.Dispose. When I navigate to my view and then away from it, I'd expect Dispose to get called (to run cleanup). I was able to achieve this by implementing a custom region behavior as discussed here, https://github.com/PrismLibrary/Prism/issues/7. All this is working fine except everything gets marked for disposal but the GC doesn't actually get rid of anything. I'm using Autofac as my IOC container and after doing some research I've concluded the reason comes down to Autofac and lifetime scopes of IDisposables, https://nblumhardt.com/2011/01/an-autofac-lifetime-primer/. Basically Autofac holds references to the IDisposable and the GC won't get rid of the old view because of this. For instance I'm registering my view in the Module as _container.RegisterTypeForNavigation(); I'm not able to register this with any sort of lifetime and I'm not sure how I'd resolve this with a lifetime specified? When I call RegionManager.RequestNavigate I don't see any sort of overloads to specify lifetime? Any ideas would be appreciated.
RegisterTypeForNavigation essentially does builder.RegisterType(type).Named<object>(name); which you can do yourself, too, of course and apply any lifetime you desire. There's no magic in registering for navigation, RegisterTypeForNavigation is just a shorthand.
To make Autofac ignore the IDisposables, one can write
builder.RegisterType<SomeView>().Named<object>(typeof(SomeView).Name).ExternallyOwned();
From the docs:
Disabling Disposal
Components are owned by the container by default and will be disposed by it when appropriate. To disable this, register a component as having external ownership:
builder.RegisterType<SomeComponent>().ExternallyOwned();
The container will never call Dispose() on an object registered with external ownership. It is up to you to dispose of components registered in this fashion.
So extending #Haukinger answer. This is what finally worked for me:
//builder.RegisterTypeForNavigation<SomeView>();
builder.RegisterType<SomeView>().Named<object>
(typeof(SomeView).Name).ExternallyOwned();
That ExternallyOwned() signals to autofac that the user is going to handle calling dispose and that autofac shouldn't track the IDisposable.
Is it possible to access session attributes inside the Vaadin SessionDestroyListener ? Or is it called after session getting destroyed ?
How the call back order regarding to HttpSessionListener, before or after ?
While the session object is available by calling sessionDestroyEvent.getSession(), its state is CLOSING and all attributes have already been removed from it (rather simple to test this...).
EDIT
#Morfic is completely right, so he gets the credit: when in a SessionDestroyListener's sessionDestroy() method, the session's attributes are, indeed, still available (I was not careful in my tests; re-did them, using the latest Vaadin release, 8.0.4).
In the _Layout.cshtml, the #Html.MvcSiteMap().Menu("viewname") caused extra 2s in each request. I found that the repository's constructor being executed several times depends on the menu's count so I guess this might be where the extra 2 seconds cames from.
Is there a way to prevent the constructors be executed once the menu rendered?
I suspect the reason for this is because you are using Security Trimming. In order to determine whether each link has access, MVCSiteMapProvider creates and releases an instance of each controller for each action. The only way to avoid this is to disable security trimming.
With security trimming enabled, it is not recommended to have any heavy processing within your constructors, as this will negatively affect performance. You should defer any processing (such as opening database connections) to later on in the request lifecycle by using an Abstract Factory to create the connection and injecting the factory into your constructor instead of the dbcontext/connection object. See this post for an example.
That said, the AuthorizeAttributeAclModule is not as efficient as it could be because when you have controllers with a lot of action methods, the same controller instance could be reused instead of creating one for each action method. You could make a custom AuthorizeAttributeAclModule and use the HttpContext.Items dictionary to request-cache each controller so they are reused instead of re-instatiated. You will need to do some refactoring to do it, though. The controller is created on line 235 and it is released on line 108. You need to make sure that the release isn't called until the after very last node is checked. You can do this by creating an IActionFilter to release them after the action is complete, but it means that action method will need to know about the same request cache (in HttpContext.Items) as the AuthorizeAttributeAclModule. You just need to implement the OnActionExecuted method to clean up the controllers from the request cache.
I use an RKObjectManager to load objects from a remote resource, and, use a tableView to display the fetched objects. When my tableView model is deallocated I cancel all current requests with
[self.objectManager cancelAllObjectRequestOperationsWithMethod:RKRequestMethodGET matchingPathPattern:self.resourcePath];
When the user reloads the view, a new model is created - Instead of creating the objectManager from scratch, I fetch the same one (I store the objectManager instance elsewhere). I'm trying to use a single object manager across the app for the same service/site - not sure if we can use multiple object managers against the same persistent object store? However, now all requests to the resource path fails with the following error.
restkit.network:RKObjectRequestOperation.m:569 Object request failed: Underlying HTTP request operation failed with error: Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)"
It looks like once I cancel against a resource path on an objectManager, I can't reload that resource via a fresh request at a later point in time. What would the best practice be to cancel current requests and reload later? In the earlier delegates version of restkit, my app would crash if I didn't remove my model/view as delegate from the object manager. I'm thinking I should still cancel my requests to avoid such issues even with the new blocks way of operation? Pointers/advice much appreciated. Thanks
Regards
George M.P.
not sure if we can use multiple object managers against the same persistent object store?
No problem with that.
When the user reloads the view, a new model is created - Instead of creating the objectManager from scratch, I fetch the same one...
If you create a new model (I guess you mean managed object store?) you should probably create a new object manager to go with it. In theory you can give the old object manager the new store but there is (or could be) a lot of internal caching that could be invalidated.
Cancelling and then reloading later should be fine, the question is what you're doing with the object store in between...
I want to add some code to log the time spent in each action call in a controller. I saw a suggestion of creating a Stopwatch inside the OnActionExecuting method of the controller and stoping it OnActionExecuted, which seems fine to me.
What I want to know is where do I have to add the started Stopwatch object so it can be read back once OnActionExecuted is called.
I was thinking on adding it to the Session, but I'm guessing this might have issues if there are simultaneous requests from the same session.
What is the best place to store this data?
Thanks
You can use HttpContext.Current.Items for objects that are related to a single request.
https://web.archive.org/web/20201202215202/https://www.4guysfromrolla.com/articles/060904-1.aspx