[The Miraculous Problem of OC Memory Management] After OC rewrites the description, there is a strange problem about memory. Please tell me why

  ios, question

First of all, I want to say that I have already solved this problem, but I don’t know why he can solve this problem by doing so. I haven’t known it for a long time, so please help me think about it.

This is a small example I made myself.

I think the problem may occur in the [WeiboMsg] forced conversion problem, which may be caused by the failure of forced conversion

What I don’t know is why a forced conversion error leads to a Wild Pointer error.

The code is attached below.

This is the class with the problem:


This is the main function:


The following is a link to the code:

Forgive me for spreading to Baidu Wangpan. I arrived in Baidu Wangpan because Baidu Wangpan was relatively fast and thought it was okay to be a turntable.


* If you can’t see the words clearly in the picture, you can open the right-click new tab page *
Or ..

main :

Weibomsg class:


__func__The type returned isconst char *, which is the normal c string, while NSString is a class. Although the two are strings, the forms stored in memory are completely different. The C string is actually a simple byte array with the last element having a value of zero, while the NSString is a class with a much more complicated structure (specifically, it can be traced back to the parent class by Always Up Pro, and it can be found that it is actually a structure).
You made a strong turn and only escaped the compiler’s check, but when it was running, it was still a C string in memory. Because of your strong turn, this c string will be treated as an NSString object, of course, you must report an error!


Remember, all variable types want the compiler to detect our errors before the program runs. When running, Central Processor does not recognize variable types! So try to avoid a strong turn unless you know what you are doing.