The BUG of automatic instantiation of non-visual objects and the bug of visual instances
PB has a hidden BUG that will occupy the memory and affect the efficiency.
Let's take an example.
(1) Create an invisible object n_base and check the Autolnstantiate attribute.
In the initialization event constructor, write messagebox ('constructor', 'pb-BUG -- constructor ')
In the destroy event destructor, write messagebox ('destuctor', 'pb-BUG -- destructor ')
(2) create a window w_1
(3) w_1 encapsulate a method of_test_bug1 to write
If 1 = 1 then
Else
N_base ln_base
End if
(4) w_1 encapsulate a method written in of_test_bug2
N_base ln_base
(5) place a button in w_1 and click "cb_1" to write it.
If 1 = 1 then
Else
N_base ln_base
End if
(6) place a button in w_1 and click "cb_2" to write it.
Of_test_bug1 ()
(7) place a button in w_1 and click "cb_3" to write it.
If 1 = 1 then
Else
Of_test_bug2 ()
End if
After that, run the simple example and click the buttons cb_1, cb_2, and cb_3 respectively.
Will find. Both cb_1 and cb_2 call the initialization and destruction events of the non-visual object n_base. But cb_3 does not.
Some methods initialize and destroy objects even if they are not called.
In this way, even if you do not want to call an object, the object will be initialized and destroyed, which will affect the efficiency and occupy the memory.
So how can we reduce this situation?
Method 1: handle it like the method in the button cb_3 click.
Method 2: remove the Autolnstantiate attribute of an invisible object and use the create method only when calling it.
N_base ln_base
Ln_base = create n_base
This reduces the impact.