moozzyk / EFInteractiveViews

MIT License
21 stars 8 forks source link

High utilisation of memoy #2

Open sekar79 opened 7 years ago

sekar79 commented 7 years ago

I use this library in my project. I have more than 600 tables in my application. I split them into multiple contexts. This loads all the views into the memory and it consumes more than 500MB of server memory. Why is it keeping the views in the memory?

moozzyk commented 7 years ago

This is not specific to this library but to EF. Any EF query/command (besides SqlQuery/SqlCommand which bypass EF pipeline) requires views. This is library is just caching views generated by EF and loading them at startup to improve the start up time. Without the library EF would have to generate the views each time the application starts (on first request) and with 600 tables it can actually make a difference but the views are exactly the same so memory usage will be the same. If you however see a difference in memory between when using EFInteractive views and when not using EFInteractive views let me know, and possibly provide dumps.

sekar79 commented 7 years ago

thanks. I have memory dump file but it is 1.2 GB. How would i upload this to you? When i selected heap view, it shows like this. ConcurrentDictionary<DbMappingViewCacheFactory, StorageMappingItemCollection> 279 MB ConcurrentDictionary+Tables<DbMappingViewCacheFactory, StorageMappingItemCollection> 279 MB ConcurrentDictionary+Node<DbMappingViewCacheFactory, StorageMappingItemCollection> 279 MB StoragemappingItemCollection 279 MB.

moozzyk commented 7 years ago

That would be here. Can you check if anything else is holding on to this instance of StorageMappingItemCollection? It's been a while since I wrote this code so I don't remember why I need to keep this but it might be an actual leak if the only thing that keeps the storageMappingItemCollection alive is the dictionary. I will try to look into this in the coming days to see if the mapping item collection can be cleaned somehow when it is no longer used.

sekar79 commented 7 years ago

Any idea why it keeps multiple instance of dictionary object? Shall i dispose the dictionary object after instantiating it?

moozzyk commented 7 years ago

I have not had a chance to look at this yet. Sorry.