Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 596

 
Juer:

All right. Let me delete them in OnDeinit(). But now I have an out of memory error already popping up during testing... That is, it won't get to OnDeinit().

So you'll create a bunch of double objects. Then everything will go to hell and you won't be able to find the end of it.

 
Artyom Trishkin:

So you create a bunch of duplicate objects. Then the whole thing will get swollen, and you won't find the end of it.

How do I know exactly where I'm not deleting objects? It's a big program :)

 
Juer:

How do I know exactly where I'm not deleting objects? It's a big programme :)

You should first find out where and how you created such a pile. If memory serves me right, you have, what, ten thousand of them? What are they? Are they historical data objects? Or what kind of objects have so many of them? An array of objects - of what?

 
Artyom Trishkin:

You should first find out where and how you made such a pile. If memory serves me right, you have tens of thousands of them there, don't you? What are they? Objects of historical data? Or what kind of objects have so many of them? An array of objects - of what?

ah, there's a lot of stuff in there. Mostly types of candles and rules. It's complicated ))

 
Juer:

How do I know exactly where I'm not deleting objects? It's a big programme :)

You don't create a new object on every tick. Of course it's possible (but not always reasonable in my opinion), but it must be more reasonable to deflate the object immediately after you finish working with it. This is the only explanation I can think of.

 
Juer:

ah, there's a lot of stuff in there. Mostly types of candles and rules. It's complicated ))

It's complicated for some and not for others. But it's up to you to sort it out now.

A word of advice. Start from scratch. Gradually add needed objects to the code and see what happens in the output - if when you change the TF or after recompiling you will get a message in the log about unremoved objects and memory leaks, then fix it. Next - again add functionality with check for correct storage, use and deletion of all objects. You must delete them yourself if you create them with new.

 
Konstantin Nikitin:

You don't create a new object on every tick. It is possible (but not always reasonable in my opinion), but it is probably more reasonable to deflate the object as soon as you finish working with it. That is the only explanation that comes to mind.

On each candle.

 
Juer:

On each candle.

Well if you don't need the previous objects, it's worth removing them straight away.

 
Konstantin Nikitin:

Well, if you don't need the previous objects, you should delete them at once.

Yeah, that's the thing. It's so confusing, the objects are in other objects and it's not so easy to delete already. Some objects depend on others, and those on third objects that depend on the first ones :)

Life is so complicated :(

 
Juer:

Yeah, that's the thing. It's so confusing, the objects are in other objects and it's not so easy to delete already. Some objects depend on others, and those on third objects that depend on the first ones :)

Life is so complicated :(

You've got it all mixed up. Incorrect planning of the task is exactly what leads to such consequences.

If objects are created in a class, the class must delete them in its destructor when it finishes. Other classes must check if the object is valid before getting a pointer to it. And in principle there shouldn't be such an intertwined relationship. It's a bit of a tangle. Complicated doesn't mean quality. Everything should be transparent and traceable. First and foremost - for you.

Reason: