Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
I use thread, to list added data,
 
No use Delegate memory occupancy 11-12M
 
Use Delegate memory occupancy 50 + M(Repeated calls to Delegate)
 
Gc can not be completely free memory,
 
help me ! Optimization code, or other solutions
 
Pseudo code:
 
main()
{
  thread start(method1); // thread run method1
}
method1()
{
 while(true)
  delegate(method2); // run method2
}
method2()
{
  listbox.items.add("test");
}
Posted 14-Nov-12 5:09am
Comments
digimanus at 14-Nov-12 11:12am
   
where is your GC.Collect?
Sergey Alexandrovich Kryukov at 14-Nov-12 13:02pm
   
Why?
--SA
Christian Graus at 14-Nov-12 14:03pm
   
NEVER call this, if you have to, it means your code is broken.
Sergey Alexandrovich Kryukov at 14-Nov-12 14:44pm
   
That's why asked "why", same thought...
--SA
qqq2195819 at 14-Nov-12 21:25pm
   
in while, To delegate can contribute little
Christian Graus at 14-Nov-12 11:23am
   
Why do you need a thread to do this ? Why do you care about 50 megabytes ? The memory usage in the task manager is not really accurate, you know.
qqq2195819 at 14-Nov-12 21:23pm
   
Is really of memory may take up more!
A thread scan or wait for data, then applied to listbox inside, I don't want to let the main thread feign death
Christian Graus at 15-Nov-12 7:51am
   
AS others have said, we cannot optimise pseudo code. Your question is meaningless. However, having a delegate called without fail in a while(true) will obviously run until it has no resources
Sergey Alexandrovich Kryukov at 14-Nov-12 13:03pm
   
Nothing is clear. Not a question. What language is this? Pseudo-code?
--SA
Christian Graus at 14-Nov-12 14:03pm
   
I assumed it was funky C# 4.5 code :P
Sergey Alexandrovich Kryukov at 14-Nov-12 14:45pm
   
Nooo-o! :-)
--SA
qqq2195819 at 14-Nov-12 21:28pm
   
C# , Because the code too much, Leaving only the main,Can be easier to understand
Sergey Alexandrovich Kryukov at 14-Nov-12 22:00pm
   
It cannot help. Nothing is clear at all.
--SA
n.podbielski at 15-Nov-12 3:52am
   
So you want others to optimize pseudo code? Really?
qqq2195819 at 15-Nov-12 9:59am
   
Hope to provide ideas, solve the problem of memory footprint
n.podbielski at 15-Nov-12 12:00pm
   
Since .net is not much about memory utilization as much as performance, since c# is not much about memory either (gc, thread safety takes memory also) maybe you should write this in C++ pointers are less demanding. Or C since it is even lighter. Or assembler. Then you can use registers an CPU cache without use of memory at all.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

this code untimely hangup every thing..
 
just add
 
method1()
{
 while(true)
{
  thread.sleep(1000);
  delegate(method2); // run method2
}
}
 
and it will work smoothly
  Permalink  
Comments
qqq2195819 at 15-Nov-12 10:03am
   
Each time you use Delegate will have Memory increases
,My purpose is to reduce the memory occupancy, thread sleep, just slow down the speed of execution, and finally memory will increase,Entrust call after hundreds of times in task manager observation, a significant increase
Sergey Alexandrovich Kryukov at 19-Nov-12 17:50pm
   
Total gibberish. A big vote of 1, sorry.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,212
1 OriginalGriff 5,498
2 CPallini 2,473
3 Richard MacCutchan 1,627
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100