0

当我使用 XCode 工具分析以下代码时,我得到了泄漏 (2.50KB) 代码是使用在 SO 上找到的 POCO C++ 从示例中编写的。泄漏是真实的还是因为 POCO C++ 使用它自己的引用计数而被报告?我是否推断出我的代码中的缺陷?

void RefComplexType::deserialize(Object::Ptr object){
if(object->has(NO) && !object->isNull(NO)){
    std::string str;
    Var no = object->get(NO);
    Object::Ptr subObject = no.extract<Object::Ptr>();
    if (subObject->has("$")&& !subObject->isNull("$")) {
        str = subObject->get("$").convert<std::string>();
    }else{
        str = no.convert<std::string>();
    }
    this->no = str;
}
if(object->has(NAME) && !object->isNull(NAME)){
    std::string str;
    Var name = object->get(NAME);
    Object::Ptr subObject = name.extract<Object::Ptr>();
    if (subObject->has("$")&& !subObject->isNull("$")) {
        str = subObject->get("$").convert<std::string>();
    }else{
        str = name.convert<std::string>();
    }

    this->name = str;
}
if(object->has(URL) && !object->isNull(URL)){
    std::string str;
    Var url = object->get(URL);
    Object::Ptr subObject = url.extract<Object::Ptr>();
    if (subObject->has("$")&& !object->isNull("$")) {
        str = subObject->get("$").convert<std::string>();
    }else{
        str = url.convert<std::string>();
    }
    this->url = str;
}
if(object->has(LOCATION) && !object->isNull(LOCATION)){
    Var locationRaw = object->get(LOCATION);
    Object::Ptr locationObject = locationRaw.extract<Object::Ptr>();
    this->location = new LocationComplexType(locationObject);
}
else {
    printf("NO! Location");

}

}

这是仪器告诉我的(运行约 10 秒后显示一个红色条)下面是调用树的一部分:

Bytes Used  # Leaks     Symbol Name
928 Bytes   20.3%   26                std::string Poco::Dynamic::Var::convert<std::string>() const
768 Bytes   16.8%   16                 Poco::Dynamic::VarHolderImpl<Poco::SharedPtr<Poco::JSON::Object, Poco::ReferenceCounter, Poco::ReleasePolicy<Poco::JSON::Object> > >::convert(std::string&) const
160 Bytes    3.5%   10                 Poco::Dynamic::VarHolderImpl<int>::convert(std::string&) const
768 Bytes   16.8%   24              Poco::JSON::Parser::parse(std::istream&)
768 Bytes   16.8%   24               Poco::JSON::Parser::readObject()
768 Bytes   16.8%   24                Poco::JSON::Parser::readRow(bool)
768 Bytes   16.8%   24                 Poco::JSON::Parser::readValue(Poco::Token const*)
768 Bytes   16.8%   24                  Poco::JSON::Parser::readObject()
768 Bytes   16.8%   24                   Poco::JSON::Parser::readRow(bool)
768 Bytes   16.8%   24                    Poco::JSON::Parser::readValue(Poco::Token const*)
768 Bytes   16.8%   24                     Poco::JSON::Parser::readArray()
768 Bytes   16.8%   24                      Poco::JSON::Parser::readElements(bool)
768 Bytes   16.8%   24                       Poco::JSON::Parser::readValue(Poco::Token const*)
768 Bytes   16.8%   24                        Poco::JSON::Parser::readObject()
768 Bytes   16.8%   24                         Poco::JSON::Parser::readRow(bool)
768 Bytes   16.8%   24                          Poco::JSON::Parser::readValue(Poco::Token const*)
768 Bytes   16.8%   24                           Poco::JSON::Parser::readObject()
768 Bytes   16.8%   24                            Poco::JSON::Parser::readRow(bool)
768 Bytes   16.8%   24                             Poco::JSON::Parser::nextToken()
768 Bytes   16.8%   24                              Poco::StreamTokenizer::next()
768 Bytes   16.8%   24                               Poco::JSON::StringToken::finish(std::istream&)
544 Bytes   11.9%   17              std::list<RefComplexType, std::allocator<RefComplexType> >::_M_create_node(RefComplexType const&)
4

0 回答 0