Errors, bugs, questions - page 1875

 

Probably because you call it manually in the OnStart() function.

Destructors of static objects are called after this function in reverse order of declaration.

 
Koldun Zloy:

Probably because you call it manually in the OnStart() function.

Destructors of static objects are called after this function in reverse order of declaration.

It seems that everything should work correctly here
template <typename T>
struct PTR
{
  T* Ptr;
  
  PTR( void )
  {
  }
  
  void operator =( T* &Value )
  {
    this.Ptr = Value;
  }
  
  ~PTR( void )
  {
    Print(__FUNCSIG__);
    delete this.Ptr;
  }
};

class CLASS
{
private:
  static PTR<CLASS> Ptr;
  static CLASS* Tmp;
  
  CLASS()
  {
    CLASS::Ptr = CLASS::Tmp;
  }
};

static PTR<CLASS> CLASS::Ptr;
static CLASS* CLASS::Tmp = new CLASS;

void OnStart()
{
}

But the leakage does occur. Where is the problem?

 
fxsaber:
I think everything must work correctly here

But the leak is happening. Where is the problem?


You create two objects and delete only one.

Why do you needCLASS::Tmp object?

 
Koldun Zloy:


You create two objects and delete only one.

Where do you create two objects?

Why do you need aCLASS::Tmp object?

Thanks to you there's no need for it anymore. But to understand the language, I'd still like to understand why the example causes leakage.

Hidden objects with hidden constructors are logical in some cases, though (probably the most pervasive one).

 

Yes, I was mistaken. You have only one object being created and not deleted.

Because when you call the constructor

  CLASS()
  {
    CLASS::Ptr = CLASS::Tmp;
  }

CLASS::Tmp still contains rubbish, not the address of the object.

 
1) The structure static PTR<CLASS> CLASS::Ptr is created;
2) class is created, new CLASS; it executes constructor CLASS()and CLASS::Ptr is assigned Null
3) CLASS::Tmp value is updated by the pointer to new CLASS
4) Deletes PTR<CLASS> structure CLASS::Ptr; executes destructor, tries to delete CLASS::Ptr (it is Null)
 
Koldun Zloy:

CLASS::Tmp still contains rubbish, not an object address.

Thank you! Somehow I didn't notice this obviousness.

Sergey Dzyublik:
1) A structure static PTR<CLASS> CLASS::Ptr is created;
2) Creates a class, new CLASS; runs constructor CLASS()andCLASS::Ptr is assigned Null
3) CLASS::Tmp value is updated by the pointer to new CLASS
4) Deletes PTR<CLASS> structure CLASS::Ptr; executes destructor, tries to delete CLASS::Ptr (it is Null)

Thank you. But it's not Null, it's trash.

 

It would be good if the mode

ChartSetInteger( 0,CHART_SHOW,false );

mode would not display arrows from trades (entries/exits). There is no need for them there at all.

 
Guys, off topic question, I'm a newbie, would like to order a job, now I have 0 on my balance, can I open a theme? or do I have to top up my account in the beginning? a little confused when they block money from my account...
 
The service is unavailable.
Gone for some valerian tincture...(