Home > Back-end >  How New and Delete in the EMB also has a problem
How New and Delete in the EMB also has a problem

Time:10-05

I have a class, ClassA, use new and delete the application will be submitted to the writing of illegal memory, define variables directly is no problem, but also is the destructor in the tip
First chance exception at $0042766 f. exception class $C0000005 with message 'access violation at 0 x0042766f: write of address 0 x73300b44'. The Process CounterText_test. Exe (11356)

Write down the code under the form of FormCreate events, also did not carry out the related operation and any other code, pure is to define and release the variable
Will use the following way:
ClasseA * PA=new ClassA ();
Delete the PA;

In the following way is all right:
ClassA A;


What a great god help analyze how be to return a responsibility?
I tried it on other classes, useful not ah

CodePudding user response:

Development environment: Windows 7 XE6

CodePudding user response:

Do you have in this ClassA code?

CodePudding user response:

Is more complex, so it is posted, but theoretically the difference between two types of code should not too big ah, is to apply for a class, a manually through the delete release, a local variable is automatically released, I tried into the destructor will be is?

CodePudding user response:

Are you delete the ClassA object later still use the object?

CodePudding user response:

Find the problem, but I don't know why
I used to in ClassA STD: : string, just remove the this variable, tried and this variable has nothing to do with useless, as long as defined

CodePudding user response:

Strange, as long as the use of STD library things will appear this problem

CodePudding user response:

The
reference 4 floor ccrun reply:
are you delete after ClassA object still using this object?


No, the other code commented out in engineering, only new and delete

CodePudding user response:

From the error message for cross-border write,
The object on the stack is not the exception, on the heap,
Stack memory generally is not an error, in the heap memory, if the memory is another program has certain error.

CodePudding user response:

http://blog.csdn.net/z397164725/article/details/11561751
Look like as described above, but I also in the Dll output STL before ah, just was compiled using 2007, and is a direct output class members of the public, now in order to better encapsulation make these parameters into a private, in the Get and Set function to read and write more!

Seems to know problem, but did not find the root cause, or very fuzzy, with superior analysis?
  • Related