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 4237370
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:45:51+00:00 2026-05-21T02:45:51+00:00

Has anyone successfully gotten IronPython running without issues in a web environment? I am

  • 0

Has anyone successfully gotten IronPython running without issues in a web environment? I am running into some issues.

First issue, I am not actually running any IronPython-specific scripts, I am implementing the Pygments library so I can get server-side syntax highlighting. The library is about 20+ files.

Besides the fact that the latest IronPython release cannot compile the scripts into a DLL (due to this issue), I do have it running successfully by just copying all the files and dependencies to my bin folder.

The problem is, I went to look at how my w3wp.exe process is doing when doing highlighting and noticed some showstopper issues:

  • Even in a totally basic, empty web site under Cassini, highlighting the code select * from table using the SQL lexer causes a 10MB jump every time I execute it (page refresh)… I am explicitly shutting down the engine and using LightweightScopes in a single function call. It starts at about 30MB and with about 20 refreshes it’s at 150MB or so.

  • In my actual web application, using the SQL lexer (same code) causes my app pool to increase about 200MB/sec (literally, I kill it when it reaches about 1GB) until it either crashes w3wp or slows my PC down to a crawl. This doesn’t happen in the empty test site and there are no problems at all in a console app with the same exact code. Other lexers like C# do not cause the huge memory leak but do have the same effect of increasing the memory each time you call the function.

This leads me to believe this a web-specific issue, considering the console app doesn’t have any problems (instantiating the runtime does cause a 20MB increase in memory, though).

I am using the 2.7 IPY release and 1.4 release of Pygments.

I don’t have the exact code with me at the moment but it looks something like:

var options = something;
options["LightweightScopes"] = ScriptRuntimeHelpers.True; // from another SO post, 'true' didn't seem to work
var engine = Python.CreateEngine(options);
//
// set up search paths here...
//
dynamic scope = whatever;
ScriptSource source = engine.CreateScriptSourceFromFile("myscript.py");

// Execute? Compile? It populates the scope at this point...
source.Compile(scope);

// execute (code, lexer name, style)
// this is a python function I have that calls the Pygments code
var highlighted = scope.generate_html("select * from table", "sql", "monokai");

engine.Shutdown();
return highlighted;

Like I said, I copied this same code in: a) a console app, b) a brand new empty web app, c) my original web app. The console app did not leak memory, but the web apps do.

I also executed the function with both the native Python (python myscript.py) and IPY (ipy myscript.py) and neither had any memory leaks.

Is there some best practice I am missing to dispose of the runtime? I plan on running this in a shared environment, so the possible workaround of instantiating the engine in a different app pool probably won’t work for me (also, that huge leak with the 200MB/s is kind of a showstopper).

Currently, unless someone has a miracle cure, I plan to scrap my code and just go with a Javascript syntax highlighter. It’s real unfortunate because Pygments is awesome…

  • 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-21T02:45:52+00:00Added an answer on May 21, 2026 at 2:45 am

    That’s quite a long story. (TLDR, sorry). This being .NET, you’re most likely looking at heap fragmentation rather than memory exhaustion.

    If you are really leaking memory then you are holding on to references too long. Review you IDisposables (especially list comprehension can hurt, especially with Linqy things like orderby and distinct tacked on).

    I once made an application run 2x as fast, when it was reliably failing by exhausting/fragmenting the heap by tacking a simple .ToList() on the largest enumerations I had to drive a big process.

    There are good memory profilers for .NET, but I currently know how to operate only mono –profiler (bad memory). A simple google will help you find a profiler you can use on your environment: let it tell you exactly what objects allocated where are fragmenting your heap


    PS. since I saw you pointing the finger on Web applications on second scanning of your question, I would add: check what references (indirectly) are being held from Session state (application, session).

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

Sidebar

Related Questions

Has anyone successfully implemented a Java based solution that uses Microsoft SQL Server 2005
Has anyone successfully talked profibus from a .NET application? If you did, what device/card
Has anyone successfully installed VS 2008 Team Developer edition on the Windows 7 beta
Has anyone been able to successfully unit test methods that are, by necessity, coupled
Has anyone looked at Yahoo's ASTRA ? It's fairly nifty, but I had some
Has anyone run into this error message before when using a timer on an
Has anyone been able to get an NHibernate-based project up and running on a
Has anyone been able to succesfully use the IE CSS hack #IEroot? I stumbled
Has anyone tried installing SQL Server 2008 Developer on a machine that already has
Has anyone ever set up Cruise Control to build an OS X Cocoa/Objective-C project?

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.