Foundation is the weight of the heavy-multi-Threading Cost ~ My memory has been eaten!

Source: Internet
Author: User

Back to Catalog

The asynchronous operation is. net4.5 launch of the new term, in fact, this thing has long ago, it is in the final analysis through the thread pool to achieve, will be a large task into a number of small any block, each thread in parallel processing one of them, after the completion of the results told the main thread, after the. More convenient, but, concurrency (lead, multithreading) is not applicable everywhere, improper use, there may be a lot of serious consequences!

Look at my program, this guy has taken up 2.6G of memory space, very scary!

The cause of this problem is that I do not have the thread this thing clear, in a call dense environment, using multi-threading, you know, this thread, the line constructor will have n multiple threads, processing speed I do not feel the ascension, but the memory eat very serious, The reason for this is because you have too many threads for your work .

So, multi-threaded, parallel, asynchronous these things are not applicable everywhere, in the call dense when you can use it, because it will eat a lot of your memory, if not to use, please limit the maximum number of thread pool, this value can be controlled within 10.

Here is an example of multithreading to eat memory

           while(true)            {               //Threadpool.setmaxthreads (ten);//Limit maximum worker threads and I/O threadsThreadPool.QueueUserWorkItem (NewWaitCallback ((a) ={concurrentdictionary<string, sendingresult> test2 =Newconcurrentdictionary<string, sendingresult>(); Test2. TryAdd (Guid.NewGuid (). ToString (),NewSendingresult {batchnumber=Guid.NewGuid (). ToString (), DbName="Zzl", Endid=1, Startid=1, TableName="Zzl", Occurdate=DateTime.Now,});                })); if(DateTime.Now.Minute = = Geneva)                {                     Break; }            }

View a Task Manager

This situation has improved when I have restricted the working thread

and If the operation is frequent (rotation service) work, if you do not use multi-threading, but based on what not to eat memory, performance is better!

Thank you for reading!

Back to Catalog

Foundation is the weight of the heavy-multi-Threading Cost ~ My memory has been eaten!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.