I’m not deallocating memory correctly here. Please help me understand what I’m doing wrong

Well it’s a database and I’m trying to deallocate the memory but I’m new to C++ and seem to be doing it wrong. Can someone who can tell just by looking see what I’ve done wrong and correct me. Please let me know how handling this problem should be done.

”’
` long long run_range_query_test(GasWorksDB &db,
unsigned age_lower_bound,
unsigned age_upper_bound,
bool db_support_range_query,
std::vector &found_record) {
auto start = high_resolution_clock::now();

    if (db_support_range_query) {
        db.find_by_age_range(age_lower_bound, age_upper_bound, found_record);
    } else {
        for (unsigned age = age_lower_bound; age <= age_upper_bound; age++) {

            std::vector<Record> found_records_by_age;
            db.find_by_age(age, found_records_by_age);
        
            for (auto &record: found_records_by_age) {
               found_record.push_back(record);
            }
        }
    }

    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    return duration.count();
}


void run_index_perf_range_query(unsigned table_size,
                                unsigned MIN_HOBBY_COUNT,
                                unsigned HOBBY_TYPE_COUNT,
                                unsigned AGE_MAX) {
    if (table_size == 0) {
        return;
    }

    /*
     * create a hash indexed db and a btree indexed db
     */
    GasWorksDB hash_indexed_db(new HashIndexGroup());
    hash_indexed_db.set_enable_index(true);

    GasWorksDB btree_indexed_db(new BtreeIndexGroup());
    btree_indexed_db.set_enable_index(true);

    /*
     * insert records
     */
    std::vector<Record *> records;
    prepare_db_for_perf_test(hash_indexed_db,
                             btree_indexed_db,
                             table_size, HOBBY_TYPE_COUNT, MIN_HOBBY_COUNT, AGE_MAX, records);

    unsigned age_lower_bound = 50;
    unsigned age_upper_bound = 52;

    /*
     * test search using hash indexed db
     */
    std::vector<Record> found_records_hash_index;
    auto hash_index_time = run_range_query_test(hash_indexed_db,
                                                age_lower_bound,
                                                age_upper_bound,
                                                false,
                                                found_records_hash_index);

    /*
     * test search using btree indexed db
     */
     std::vector<Record> found_records_btree_index;
    auto btree_index_time = run_range_query_test(btree_indexed_db,
                                                 age_lower_bound,
                                                 age_upper_bound,
                                                 true,
                                                 found_records_btree_index);

    /*
     * test search without index
     */
     std::vector<Record> found_records_no_index;
    btree_indexed_db.set_enable_index(false);    // disable index
    auto no_index_time = run_range_query_test(btree_indexed_db,
                                              age_lower_bound,
                                              age_upper_bound,
                                              true,
                                              found_records_no_index);

    /*
     * validate consistent search results regardless of db
     */
    ASSERT_TRUE(!found_records_no_index.empty());
    ASSERT_TRUE(!found_records_hash_index.empty());
    ASSERT_TRUE(!found_records_btree_index.empty());

    ASSERT_EQ(found_records_no_index.size(), found_records_hash_index.size());
    ASSERT_EQ(found_records_no_index.size(), found_records_btree_index.size());

    std::set<unsigned> btree_index_ids;
    for (auto &record: found_records_btree_index) {
        btree_index_ids.insert(record.get_id());
    }

    std::set<unsigned> btree_unindex_ids;
    for (auto &record: found_records_no_index) {
        btree_unindex_ids.insert(record.get_id());
    }

    std::set<unsigned> hash_index_ids;
    for (auto &record: found_records_hash_index) {
        hash_index_ids.insert(record.get_id());
    }

    ASSERT_EQ(hash_index_ids, btree_index_ids);
    ASSERT_EQ(hash_index_ids, btree_unindex_ids);


    std::cout << table_size << ","
              << hash_index_time
              << ","
              << btree_index_time
              << ","
              << no_index_time
              << std::endl;

 for (auto record : records) {
    delete record;
}
records.clear();
}`

”’

I tried to delete the record from the bottom, but it’s not working when I run on a linux machine.

New contributor

Lexi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật