msgraph-sdk-ruby icon indicating copy to clipboard operation
msgraph-sdk-ruby copied to clipboard

Memory leak?

Open KevinColemanInc opened this issue 4 years ago • 0 comments

I am trying to pull down ~1,500 emails with png and pdf attachments and its killing my server.

Looking at the code, I see the gem is keeping in memory the last 1000 collection objects.

https://github.com/microsoftgraph/msgraph-sdk-ruby/blob/4ee17fd74e729c362bb452f683c973d0a42af28f/lib/microsoft_graph/collection_association.rb#L222

I don't have time to investigate this further, but my machine doesn't have the resources to maintain ~1500 pdf files in memory. It would be better if with each fetch from the API, we GC the last page, since I not longer need it.

My quick fix in my active job worker like this:

    @emails = []
    outlook_service.latest_messages.each do |message|
      email = OutlookEmail::CreateEmailService.new(message: message,
                                           domain: @domain,
                                           company: @domain.company).email!
      @emails.push(email)
      break if @emails.length > 10
    end

    FetchOutlookJob.perform_later(domain_id) if @emails.any?

KevinColemanInc avatar Aug 28 '19 03:08 KevinColemanInc