Calculation_function1=New add_com. Jisuan 'load when initializing
For I=1 To 1000
Calculation_function1. Add (1, c, I, 2)
TextBox1. Text=c
Next
N=Marshal. ReleaseComObject (calculation_function1)
But when I use the following method, memory has been very stable, my question is, is also called calculation_function1, initialization and release of different location (for example, I these two examples) why will cause memory a release is completed, a release is not complete? Initialized the above procedures, outside the circle is what I want, because every time to initialize the com component when the speed is slow, so also is to complete a cycle, faster computing speed significantly above, what is the way to modify the code which guarantee the calculation speed, memory and can correct release at the same time? First thanked,
For I=1 To 1000
Calculation_function1=New add_com. Jisuan 'load when initializing
Calculation_function1. Add (1, c, I, 2)
TextBox1. Text=c
N=Marshal. ReleaseComObject (calculation_function1)
Next
CodePudding user response:
Obviously this is memory leaks in your leaked in the add method, due to the following every time is over, will release the entire object so you can't see the memory increases obviously, but the above, every time the calculations in more memory, and you finally released, so you have to see that you write this function variables are local declarations, then there is no free memory, this is my personal view, wrong words to discuss ha, don't like do not spray, the quality of discussion,CodePudding user response: