when get dynamic compiled assemblies unloaded?

edited 1:40AM in FastReport .NET
Hello,

since all (temporary) compiled assemblies produced and attached by report.Prepare() are loaded into the default AppDomain they never will be unloaded -- when will the process be out of handles?

Comments

  • edited May 2010
    Hello,

    Dynamic assemblies are never unloaded. If you prepare thousands of reports, you will run out of memory (each report assembly is about 50kb).

    The solution is to create new AppDomain and execute the report in it. When you no longer need the report, unload the domain. Creating/unloading domains is rather slow (10x slower than just creating a new instance of report), that's why we didn't implement that method in FastReport. But, at the application level, you may optimize this process. You may create a domain and use it, say, 1000 times, then unload it. In this case the performance hit will not so big.
        AppDomain appDomain = null;
        // domain time-to-live
        int domainTTL = 0;
    
    
    ...
            if (appDomain == null)
            {
                AppDomainSetup appDomainSetup = new AppDomainSetup();
                appDomainSetup.ShadowCopyFiles = "false";
                appDomainSetup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
                appDomain = AppDomain.CreateDomain("new domain", AppDomain.CurrentDomain.Evidence, appDomainSetup);
            }
    
            Worker worker = appDomain.CreateInstanceAndUnwrap(
                this.GetType().Assembly.FullName, typeof(Worker).FullName) as Worker;
    
            worker.Print();
    
            // unload the domain after 1000times of use
            domainTTL++;
            if (domainTTL > 1000)
            {
                AppDomain.Unload(appDomain);
                appDomain = null;
                domainTTL = 0;
            }
    ...
    
    // this class is doing actual printing
    public class Worker : MarshalByRefObject
    {
        public void Print()
        {
            using (Report report = new Report())
            {
                report.Load("file.frx");
                report.RegisterData(ds, "Data");
    
                Config.ReportSettings.ShowProgress = false;
                report.Prepare();
            }
        }
    }
    

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.