From 776aee876d723db68249e85583eb40aa12d9483e Mon Sep 17 00:00:00 2001 From: Ladislav Smola Date: Fri, 20 Jan 2017 14:52:19 +0100 Subject: [PATCH] Nullify array of the to be 'deleted' objects Nullify array of the to be 'deleted' objects, this was causing a reference and the AR objects were not GCed then. --- app/models/ems_refresh/save_inventory.rb | 2 ++ app/models/ems_refresh/save_inventory_helper.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/models/ems_refresh/save_inventory.rb b/app/models/ems_refresh/save_inventory.rb index a70196a4e17..68610327daf 100644 --- a/app/models/ems_refresh/save_inventory.rb +++ b/app/models/ems_refresh/save_inventory.rb @@ -53,6 +53,8 @@ def save_vms_inventory(ems, hashes, target = nil) _log.info "#{log_header} Duplicate unique values found: #{dup_vms_uids.inspect}" unless dup_vms_uids.empty? invalids_found = false + # Clear vms, so GC can clean them + vms = nil ActiveRecord::Base.transaction do hashes.each do |h| diff --git a/app/models/ems_refresh/save_inventory_helper.rb b/app/models/ems_refresh/save_inventory_helper.rb index 618484ade98..ed778b060ed 100644 --- a/app/models/ems_refresh/save_inventory_helper.rb +++ b/app/models/ems_refresh/save_inventory_helper.rb @@ -43,6 +43,8 @@ def save_inventory_multi(association, hashes, deletes, find_key, child_keys = [] end deletes = deletes.to_a deletes_index = deletes.index_by { |x| x } + # Alow GC to clean the AR objects as they are removed from deletes_index + deletes = nil child_keys = Array.wrap(child_keys) remove_keys = Array.wrap(extra_keys) + child_keys