Home > Net >  Vb.net calls generated by the MATLAB com components of memory problems
Vb.net calls generated by the MATLAB com components of memory problems

Time:09-16

Everyone a great god, the younger brother using matlab function (a simple summation function) to generate the com components, and then call in the vb.net, when invoked, found that memory will increase if you use the following way, ReleaseComObject returns the value of n is 0, said should already be released out, but memory hasn't been dropped,
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:

1/f, reference of study medicine program trip reply:
, 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, the calculation of every time an increase in memory, and you finally released, so you have to look at you write this function variables are local declarations, then there is no free memory, this is my personal view, wrong words to discuss, don't like do not spray, quality discussion,

Thank you, I the add function of MATLAB as follows, it is a relatively simple function, the inside is what needs to be released? Mostly I didn't release matlab object before, just empty when used the clear, but if I'm in the clear, c, there is no return value,
The function c=add (a, b)
C=2 * a + b;
end

CodePudding user response:

Call MATLAB itself is very slow, this is no way to temporarily, MATLAB calculation every time the default will save the results in memory, since can't clear after calculation, the clear before calculation,
  • Related