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

  • Home
  • SEARCH
  • 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 6360787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:41:36+00:00 2026-05-24T23:41:36+00:00

I am running a django app that includes matplotlib and allows the user to

  • 0

I am running a django app that includes matplotlib and allows the user to specify the axes of the graph. This can result in ‘Overflow Error: Agg complexity exceeded’

When that happens up to 100MB of RAM get tied up. Normally I free that memory up using fig.gcf(), plot.close(), and gc.collect(), but the memory associated with the error does not seem to be associated with the plot object.

Does anyone know how I can release that memory?

Thanks.

Here is some code that gives me the Agg Complexity Error.

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np      
import gc

a = np.arange(1000000)
b = np.random.randn(1000000)

fig = plt.figure(num=1, dpi=100, facecolor='w', edgecolor='w')
fig.set_size_inches(10,7)
ax = fig.add_subplot(111)
ax.plot(a, b)

fig.savefig('yourdesktop/random.png')   # code gives me an error here

fig.clf()    # normally I use these lines to release the memory
plt.close()
del a, b
gc.collect()
  • 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-24T23:41:36+00:00Added an answer on May 24, 2026 at 11:41 pm

    I assume you can run the code you posted at least once. The problem only manifests itself after running the posted code many times. Correct?

    If so, the following avoids the problem without really identifying the source of the problem.
    Maybe that is a bad thing, but this works in a pinch: Simply use multiprocessing to run the memory-intensive code in a separate process. You don’t have to worry about fig.clf() or plt.close() or del a,b or gc.collect(). All memory is freed when the process ends.

    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt
    import numpy as np      
    
    import multiprocessing as mp
    
    def worker():
        N=1000000
        a = np.arange(N)
        b = np.random.randn(N)
    
        fig = plt.figure(num=1, dpi=100, facecolor='w', edgecolor='w')
        fig.set_size_inches(10,7)
        ax = fig.add_subplot(111)
        ax.plot(a, b)
    
        fig.savefig('/tmp/random.png')   # code gives me an error here
    
    if __name__=='__main__':
        proc=mp.Process(target=worker)
        proc.daemon=True
        proc.start()
        proc.join()
    

    You don’t have to proc.join() either. The join will block the main process until the worker completes. If you omit the join, then the main process simply continues with the worker process working in the background.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running a Django app using FastCGI and lighttpd. Can somebody explain me what
I'm using django with app-engine-patch and I'm having this wierd problem running manage.py dumpdata
I have a simple django app that is using only the admin. This is
I have a Django app running on Windows (via Apache + mod_wsgi) that's CPU-bound.
I am building my first django app that uses user authentication and I'm using
I'm running a Django app on Apache + mod_python. When I make some changes
I'm running Django 1.0 and I'm close to deploying my app. As such, I'll
HI I have a django application running on app engine and I want to
We have a Django app running on apache server (mod_python) on a windows machine
Background : Running a PostgreSQL database for a Django app (Django 1.1.1, Python2.4, psycopg2

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.