Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6676743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:01:49+00:00 2026-05-26T04:01:49+00:00

I have written a small webapp using the flask framework that involves plotting using

  • 0

I have written a small webapp using the flask framework that involves plotting using matplotlib. The problem is that every time I create the plot, the process consumes more memory.

I have deployed the app using mod_wsgi with a .wsgi file looking simply like this:

from yourapplication import app as application

The problems start when I access the url which creates the plot. The function creates a plotter object which, when initilized, takes the relevant data from a sqlite3 database (the data consist of about 30 integers and equally many datetime objects), creates a plot using matplotlib and returning a StringIO object which then is displayed on screen.

This is the end of the function. The whole class can be seen here

    canvas = FigureCanvas(fig)
    png_output = StringIO.StringIO()
    canvas.print_png(png_output)
    return png_output.getvalue()

When I visit the site, a process is created with about 25MB of reserved memory. The first time I create a plot it grows to 30MB and then with about 1MB for each time I use the plotter class. The default settings were using 5 process which consumed way too much memory (was up to 150MB within minutes and I’m only allowed 80MB).

I’m very new to all things involved here (web frameworks, apache, databases) so I don’t have any feeling of were things might be going wrong, so any ideas are highly appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:01:50+00:00Added an answer on May 26, 2026 at 4:01 am

    Doing this after each call to the plot_month function solved the leak.

    import gc
    gc.collect()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a small Asp.net application using Entity Framework. A Stored Procedure accepts
I have written a small util in an app that syncs the time from
i have written a small webapp using spring-security and spring-mvc with an annotation based
I have written a small Perl script and now I would like to create
I have written a small chat app that uses mysql + php to facilitate
I have written a small app that puts my bluetooth in discoverable mode for
I have written a small XML validator, that takes in an XML file and
I have written a small PHP framework and I want to make a website
I have written a small program using Borland's C++ builder, and along the way,
I have written a small PHP file that gets the information that was posted

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.