Click here to Skip to main content
15,887,683 members
Home / Discussions / C#
   

C#

 
GeneralRe: Report Builder in Visual Studio Pin
milo-xml12-Jan-16 1:27
professionalmilo-xml12-Jan-16 1:27 
AnswerRe: Report Builder in Visual Studio Pin
Gerry Schmitz11-Jan-16 4:54
mveGerry Schmitz11-Jan-16 4:54 
GeneralRe: Report Builder in Visual Studio Pin
milo-xml11-Jan-16 5:08
professionalmilo-xml11-Jan-16 5:08 
GeneralRe: Report Builder in Visual Studio Pin
Gerry Schmitz11-Jan-16 5:29
mveGerry Schmitz11-Jan-16 5:29 
AnswerRe: Report Builder in Visual Studio Pin
Mycroft Holmes11-Jan-16 12:04
professionalMycroft Holmes11-Jan-16 12:04 
QuestionC# Run Powershell with elevated rights Pin
Member 1085106210-Jan-16 15:06
Member 1085106210-Jan-16 15:06 
AnswerRe: C# Run Powershell with elevated rights Pin
Garth J Lancaster10-Jan-16 16:54
professionalGarth J Lancaster10-Jan-16 16:54 
QuestionMemory leak trouble with Linq to Sql and multiple threads Pin
JD869-Jan-16 14:07
JD869-Jan-16 14:07 
I'm having some issue with my code in my Windows Service not releasing memory.

In short my Windows Service basically created about 8 timers that elapsed every X minutes which called a method that queried data from Exchange and stored in the database.

What I have noticed is the memory always climbed to the point it would crash the service when it reached maximum (32-bit process)

I switched from using timers to using the Quartz library but experienced the same results.

Here is an example of one of the timers jobs:
C#
public class Get_MailboxDatabaseSizesTask : IJob
   {
       private static readonly ILog logger = LogManager.GetLogger("Get_MailboxDatabaseSizesTask");

       public void Execute(IJobExecutionContext context)
       {
           CloudPanelDbContext db = null;
           ExchActions powershell = null;
           int processedCount = 0;

           try
           {
               db = new CloudPanelDbContext(Config.ServiceSettings.SqlConnectionString);
               db.Connection.Open();

               powershell = new ExchActions();
               var mailboxDatabases = powershell.Get_MailboxDatabaseSizes();
               db.StatMailboxDatabaseSizes.InsertAllOnSubmit(mailboxDatabases);
               db.SubmitChanges();

               processedCount = mailboxDatabases.Count;
               mailboxDatabases = null;
           }
           catch (Exception ex)
           {
               logger.ErrorFormat("Failed to retrieve mailbox database sizes: {0}", ex.ToString());
           }
           finally
           {
               if (powershell != null)
                   powershell.Dispose();

               if (db != null)
                   db.Dispose();

               logger.InfoFormat("Processed a total of {0} mailbox databases", processedCount);
           }

       }
   }



As you can see I am disposing of my context and my ExchActions class... I solved the memory issue by adding this to the end of each Execute method:

C#
GC.Collect();
GC.WaitForPendingFinalizers();



Its not ideal but its working.... but why do I have such a memory problem without it? Where should I look?
AnswerRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Dave Kreskowiak9-Jan-16 18:05
mveDave Kreskowiak9-Jan-16 18:05 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
JD8610-Jan-16 16:41
JD8610-Jan-16 16:41 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Dave Kreskowiak10-Jan-16 17:19
mveDave Kreskowiak10-Jan-16 17:19 
AnswerRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Luc Pattyn9-Jan-16 18:07
sitebuilderLuc Pattyn9-Jan-16 18:07 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Dave Kreskowiak9-Jan-16 18:20
mveDave Kreskowiak9-Jan-16 18:20 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Luc Pattyn9-Jan-16 18:29
sitebuilderLuc Pattyn9-Jan-16 18:29 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Dave Kreskowiak9-Jan-16 18:36
mveDave Kreskowiak9-Jan-16 18:36 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
JD8610-Jan-16 16:31
JD8610-Jan-16 16:31 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Luc Pattyn10-Jan-16 17:00
sitebuilderLuc Pattyn10-Jan-16 17:00 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
JD8610-Jan-16 17:06
JD8610-Jan-16 17:06 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Luc Pattyn11-Jan-16 2:31
sitebuilderLuc Pattyn11-Jan-16 2:31 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Richard MacCutchan10-Jan-16 20:58
mveRichard MacCutchan10-Jan-16 20:58 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Luc Pattyn11-Jan-16 2:21
sitebuilderLuc Pattyn11-Jan-16 2:21 
AnswerRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Gerry Schmitz10-Jan-16 7:42
mveGerry Schmitz10-Jan-16 7:42 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Dave Kreskowiak10-Jan-16 8:29
mveDave Kreskowiak10-Jan-16 8:29 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
Gerry Schmitz10-Jan-16 9:04
mveGerry Schmitz10-Jan-16 9:04 
GeneralRe: Memory leak trouble with Linq to Sql and multiple threads Pin
JD8610-Jan-16 16:33
JD8610-Jan-16 16:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.