Skip to content

Commit

Permalink
Nullify array of the to be 'deleted' objects
Browse files Browse the repository at this point in the history
Nullify array of the to be 'deleted' objects, this was causing
a reference and the AR objects were not GCed then.
  • Loading branch information
Ladas committed Apr 11, 2017
1 parent df7efdb commit 776aee8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/ems_refresh/save_inventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
2 changes: 2 additions & 0 deletions app/models/ems_refresh/save_inventory_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 776aee8

Please sign in to comment.