diff --git a/RecoJets/JetProducers/plugins/FastjetJetProducer.cc b/RecoJets/JetProducers/plugins/FastjetJetProducer.cc index 451e646977b74..2471ed34befaf 100644 --- a/RecoJets/JetProducers/plugins/FastjetJetProducer.cc +++ b/RecoJets/JetProducers/plugins/FastjetJetProducer.cc @@ -194,6 +194,11 @@ void FastjetJetProducer::produce( edm::Event & iEvent, const edm::EventSetup & i } + // fjClusterSeq_ retains quite a lot of memory - about 1 to 7Mb at 200 pileup + // depending on the exact configuration; and there are 24 FastjetJetProducers in the + // sequence so this adds up to about 60 Mb. It's allocated every time runAlgorithm + // is called, so safe to delete here. + fjClusterSeq_.reset(); } @@ -317,6 +322,12 @@ void FastjetJetProducer::produceTrackJets( edm::Event & iEvent, const edm::Event LogDebug("FastjetTrackJetProducer") << "Put " << jets->size() << " jets in the event.\n"; iEvent.put(jets); + // Clear the work vectors so that memory is free for other modules. + // Use the trick of swapping with an empty vector so that the memory + // is actually given back rather than silently kept. + decltype(fjInputs_)().swap(fjInputs_); + decltype(fjJets_)().swap(fjJets_); + decltype(inputs_)().swap(inputs_); } diff --git a/RecoJets/JetProducers/plugins/VirtualJetProducer.cc b/RecoJets/JetProducers/plugins/VirtualJetProducer.cc index 35d8b4610cc11..f8650050b1e1f 100644 --- a/RecoJets/JetProducers/plugins/VirtualJetProducer.cc +++ b/RecoJets/JetProducers/plugins/VirtualJetProducer.cc @@ -402,6 +402,13 @@ void VirtualJetProducer::produce(edm::Event& iEvent,const edm::EventSetup& iSetu output( iEvent, iSetup ); LogDebug("VirtualJetProducer") << "Wrote jets\n"; + // Clear the work vectors so that memory is free for other modules. + // Use the trick of swapping with an empty vector so that the memory + // is actually given back rather than silently kept. + decltype(fjInputs_)().swap(fjInputs_); + decltype(fjJets_)().swap(fjJets_); + decltype(inputs_)().swap(inputs_); + return; }