Amessage的clear会清除对象并释放内存空间

项目中用了Amessage,通过调试发现:

定义一个向量集合:

vector<DateStructure*> list;

其中DateStructure是一个继承Refbase的类

然后往list中添加数据

DateStructure*   data = new DateStructure();

list.push_back(data);

然后将这个list通过Amessage发送

sp<Amessage> msg =  new Amessage(AWhatSend, ***)

int size = list.size();

msg->setInt32("size", size);

if(size == 0) {

    return;

}

for(int i = 0; i<data.size(); i++) {

    string tag = to_string(i) 

    msg->setObject(tag, data[i]);

}

msg->post();

然后在onMessageReceived方法中接收这个message,然后执行list.clear()清除这个操作,然后发现对象的内存空间也被清除了,而这个清除操作是Amessage做的,Amessage.clear时发现会将DataStructure之前new出来的所有对象都清除,并释放内存空间。

int size;

msg->findInt32("size", &size);

if(size == 0) {

    return;

}

vector<DataStructure*> list;

for(int i = 0; data.size; i++) {j

    string tagid= to_string(i);
    const char* tag = tagid.c_str();

    RefBase obj;

    msg->findObject(tag, &obj);

    DataStructure* obj1 = nullptr;
    obj1 = static_cast<DataStructure*>(obj.get());

    list.push_back(obj1);

}

调用堆栈如下 

01-09 07:59:26.883  1022  1969 D ~DataStructure: #00 pc 00007cad  /vendor/bin/hw/vendor.xxx.hardware.yyy@1.0-service (android::DataStructure::~DataStructure()+68)
01-09 07:59:26.883  1022  1969 D ~DataStructure: #01 pc 00007d0b  /vendor/bin/hw/vendor.xxx.hardware.yyy@1.0-service (android::DataStructure::~DataStructure()+2)
01-09 07:59:26.883  1022  1969 D ~DataStructure: #02 pc 0000a725  /apex/com.android.vndk.v32/lib/libutils.so (android::RefBase::decStrong(void const*) const+68)
01-09 07:59:26.883  1022  1969 D ~DataStructure: #03 pc 00011da3  /vendor/lib/vndk/libstagefright_foundation.so (android::AMessage::clear()+86)
01-09 07:59:26.883  1022  1969 D ~DataStructure: #04 pc 00011d05  /vendor/lib/vndk/libstagefright_foundation.so (android::AMessage::~AMessage()+16)
01-09 07:59:26.883  1022  1969 D ~DataStructure: #05 pc 00011db7  /vendor/lib/vndk/libstagefright_foundation.so (android::AMessage::~AMessage()+2)
01-09 07:59:26.883  1022  1969 D ~DataStructure: #06 pc 0000a725  /apex/com.android.vndk.v32/lib/libutils.so (android::RefBase::decStrong(void const*) const+68)
01-09 07:59:26.883  1022  1969 D ~DataStructure: #07 pc 00010977  /vendor/lib/vndk/libstagefright_foundation.so (android::ALooper::loop()+510)
01-09 07:59:26.883  1022  1969 D ~DataStructure: #08 pc 0000d303  /apex/com.android.vndk.v32/lib/libutils.so (android::Thread::_threadLoop(void*)+302)
01-09 07:59:26.883  1022  1969 D ~DataStructure: #09 pc 0000cdc3  /apex/com.android.vndk.v32/lib/libutils.so (thread_data_t::trampoline(thread_data_t const*)+262)
01-09 07:59:26.883  1022  1969 D ~DataStructure: #10 pc 00080d97  /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+40)
01-09 07:59:26.883  1022  1969 D ~DataStructure: #11 pc 00039d93  /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+30)

 

 

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-12 12:36:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-12 12:36:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-12 12:36:03       82 阅读
  4. Python语言-面向对象

    2024-01-12 12:36:03       91 阅读

热门阅读

  1. 数据结构---双向链表

    2024-01-12 12:36:03       56 阅读
  2. 灰色神经网络的回归分析

    2024-01-12 12:36:03       57 阅读
  3. MongoDB分片集群搭建

    2024-01-12 12:36:03       48 阅读
  4. Qt模型视图框架:QDataWidgetMapper 数据映射

    2024-01-12 12:36:03       56 阅读
  5. 算法训练营Day37

    2024-01-12 12:36:03       53 阅读