bltoolkit icon indicating copy to clipboard operation
bltoolkit copied to clipboard

Can't clear internal BLToolKit cache explicitly

Open TimeCoder opened this issue 12 years ago • 8 comments

Hello, Igor! I have some troubles with reading big data. For example, I do that:

while (true) { objects = dbManager.SetCommand(fullQuery, ...params...).ExecuteList<TImpl>(); }

As you can see, each iteration clears reference on previos data block. GC periodically clears the memory. But after 2 hours proccess takes almost 1Gb RAM! I suppose that readed objects cached in some internal cache of BLTK. Am I right? In EntityFramework this situation resolves by "no tracking changes" flag. Here I have to dispose DBManager every cicle iteration. Is there another way? Some dbManager.ClearCache ? :-)

TimeCoder avatar Dec 20 '13 09:12 TimeCoder

The ExecuteList method does not cache anything.

igor-tkachev avatar Dec 21 '13 20:12 igor-tkachev

Usually GC takes as much memory as it can if other applications do not need it. So, I do not think this is a problem.

igor-tkachev avatar Dec 21 '13 20:12 igor-tkachev

It's very strange... Why when I do this:

using (var dbManager = new DBManager())
{
    while (true)   // ~ 10 millions objects total,  10,000 objects in one iteration  
    {
        objects = dbManager.SetCommand(fullQuery, ...params...).ExecuteList();
    }
}

Memory usage grows up to 1Gb (and my app throw OutOfMemoryException), but if I do this:

while (true)   // ~ 10 millions objects total,  10,000 objects in one iteration  
{
    using (var dbManager = new DBManager())
    {
         objects = dbManager.SetCommand(fullQuery, ...params...).ExecuteList();
    }
}
  • everything is OK, memory usage fluctuates around the mark of 300Mb ?

TimeCoder avatar Dec 22 '13 13:12 TimeCoder

i'v done mostly the same test:

        static void Main(string[] args)
        {
            using (var db = new DbManager())
            {
                for (int i = 0; i < 10000; i++)
                {
                    var e = db.SetCommand("select * from transactiondetail").ExecuteList<Trans>();
                }

                Console.ReadLine();
            }

and have no problem with memory so i think it would be better to look with memory profiler where are the roots for objects (memory leak) in your case

for ex. i'v faced with memory leak by event handlers when cached objects are subscribed to events of "selected" objects

ili avatar Dec 24 '13 10:12 ili

Thanks, i'll try it. By the way, your code creates SAME objects many times. In my case, every ExecuteList selects next page of uniq objects - may be this is important.

TimeCoder avatar Dec 25 '13 04:12 TimeCoder

mostly it should not mean... but memory profiler should show the truth.

please, tell about results, it is interesting case

ili avatar Dec 25 '13 05:12 ili

What profiler should I use? Standart PerfMonitor?

TimeCoder avatar Dec 26 '13 04:12 TimeCoder

any .Net memory profiler, i think

dotTrace for ex

ili avatar Dec 30 '13 14:12 ili