bool M2MObject::remove_object_instance(uint16_t inst_id) { tr_debug("M2MObject::remove_object_instance(inst_id %d)", inst_id); bool success = false; if(!_instance_list.empty()) { M2MObjectInstance* obj = NULL; M2MObjectInstanceList::const_iterator it; it = _instance_list.begin(); int pos = 0; for ( ; it != _instance_list.end(); it++, pos++ ) { if((*it)->instance_id() == inst_id) { // Instance found and deleted. obj = *it; String obj_name = name(); obj_name.push_back('/'); obj_name.append_int(obj->instance_id()); obj->remove_resource_from_coap(obj_name); _instance_list.erase(pos); delete obj; success = true; break; } } } return success; }