Leaked memory

 

Hello,

when running the code below MT4 prints:

2020.07.28 11:42:00.097    Class EURUSD,M1: 16 bytes of leaked memory
2020.07.28 11:42:00.097    Class EURUSD,M1: 1 object of type test left
2020.07.28 11:42:00.097    Class EURUSD,M1: 1 undeleted objects left


#property strict

void OnStart(){

     test t = new test();
}

class test{
  
};

How to set the memory free again after creating a new object?

 
Let me put my question more precisely: How to create instances of the class above without producing a memory leak?
 

Did you know that MQL 4 comes with documentation? It's that thing where they briefly list and explain features of the language and it's available as help file in the editor and as a web site.

There you can read about OOP basics.

Among other things there is a documentation on Object Delete Operator delete, which is also linked from the page on Object Create Operator new

Object Delete Operator delete - Operators - Language Basics - MQL4 Reference
Object Delete Operator delete - Operators - Language Basics - MQL4 Reference
  • docs.mql4.com
Object Delete Operator delete - Operators - Language Basics - MQL4 Reference
 
Drazen Penic:

Did you know that MQL 4 comes with documentation? It's that thing where they briefly list and explain features of the language and it's available as help file in the editor and as a web site.

There you can read about OOP basics.

Among other things there is a documentation on Object Delete Operator delete, which is also linked from the page on Object Create Operator new

Ah cmon, don´t be like that. If you know the answer to a question it is great if you post it. But try to cut all that <Deleted> beside it. That only spoils the atmosphere here.
 
Jan Tarnogrocki:
Ah cmon, don´t be like that. If you know the answer to a question it is great if you post it. But try to cut all that <Deleted> beside it. That only spoils the atmosphere here.


Cute, not just unfamiliar with the concept of the documentation and generally lazy, also easily offended.

You waited 24 hours from your question, and it didn't occur to you to check the help file?

Open editor, click on "new" keyword in your code, press F1, read. 

There is exactly 5, not very long sentences and code example. The last sentence references the "delete" operator.

How hard is that? 


P.S.

I noticed that being mildly sarcastic usually helps people learn to check the documentation before asking obvious questions.

P.P.S

Since I'm not a native English speaker, I use this forum to practice being sarcastic to random people on the internet. Also, seeking another hobby, but haven't found anything better yet. 

Just consider yourself half lucky today. You got an answer and some unwanted <Deleted> besides. It's the price of doing business on the internet.

 
Drazen Penic:


Cute, not just unfamiliar with the concept of the documentation and generally lazy, also easily offended.

You waited 24 hours from your question, and it didn't occur to you to check the help file?

Open editor, click on "new" keyword in your code, press F1, read. 

There is exactly 5, not very long sentences and code example. The last sentence references the "delete" operator.

How hard is that? 


P.S.

I noticed that being mildly sarcastic usually helps people learn to check the documentation before asking obvious questions.

P.P.S

Since I'm not a native English speaker, I use this forum to practice being sarcastic to random people on the internet. Also, seeking another hobby, but haven't found anything better yet. 

Just consider yourself half lucky today. You got an answer and some unwanted <Deleted> besides. It's the price of doing business on the internet.

I am still thinking you can do better! In real life you might be a nice guy I can imagine.
 
     test t = new test();
  1. You create an object on the heap. (new)
  2. You copy the object to object t.
  3. You loose the handle (;)
Either make t a pointer and delete the object before t goes out of scope, or don't use new.