Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default not releasing excel objects..pl see this simple code.

Please help...i tried so many things but I can't get all Excel objects
cleaned up. Here is my whole code...if I comment out everything in
for() loop below excel objects get cleaned up. otherwise I can see them
in Task Manager...its so weird.

Appreciate your help.
thanks

Excel.Application dstExcel = new Excel.ApplicationClass();
Excel._Workbook dstWb = dstExcel.Workbooks.Open(eventdir,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value,
Missing.Value, Missing.Value, Missing.Value);
Excel._Worksheet dstWsh = (Excel._Worksheet)dstWb.Sheets.get_Item(2);

int i = 0;
string vend, perc;

for ( i = 15; i <= 34; i++ )
{
if ( ((Excel.Range)dstMsh.Cells[i,4]).Value2 != null )
{
perc = ((Excel.Range)dstMsh.Cells[i,4]).Value2.ToString();
}
else
{
perc = "";
}

if ( ((Excel.Range)dstMsh.Cells[i,2]).Value2 != null )
{
vend = ((Excel.Range)dstMsh.Cells[i,2]).Value2.ToString();
}
else
{
vend = "";
}

// process 'perc' and 'vend' strings

}

// export excel chart
Excel.Range chartRange = dstMsh.get_Range("B15", "D" +
chartData.ToString());
Excel.ChartObjects chObjs =
(Excel.ChartObjects)dstMsh.ChartObjects(Type.Missi ng);
Excel.ChartObject chObj = chObjs.Add(100, 200, 300, 200);
Excel.Chart chart = chObj.Chart;

chart.SetSourceData(chartRange, Type.Missing);
chart.ChartArea.AutoScaleFont = false;
chart.ChartType = Excel.XlChartType.xlBarClustered;

string imgDir = "C:\\inetpub\\wwwroot\\apac2\\images\\";
string imgSaveAs = getCurrentTime()+ "_chart.JPG";
chart.Export(imgDir + imgSaveAs, "JPEG", false);

imgChart.Visible = true;
imgChart.ImageUrl = "images\\" + imgSaveAs;

System.Runtime.InteropServices.Marshal.ReleaseComO bject (chartRange);
System.Runtime.InteropServices.Marshal.ReleaseComO bject (chart);
System.Runtime.InteropServices.Marshal.ReleaseComO bject (chObjs);
System.Runtime.InteropServices.Marshal.ReleaseComO bject (chObj);
chartRange = null;
chObjs = null;
chObj = null;
chart = null;

System.Runtime.InteropServices.Marshal.ReleaseComO bject (dstMsh);
dstMsh = null;

dstWb.Close(false, Missing.Value, Missing.Value);
dstExcel.Workbooks.Close();
dstExcel.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject (dstExcel);
System.Runtime.InteropServices.Marshal.ReleaseComO bject (dstWb);
System.Runtime.InteropServices.Marshal.ReleaseComO bject (dstWsh);

dstWsh = null;
dstWb = null;
dstExcel = null;

GC.Collect();
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Releasing arrays? SiriS Excel Discussion (Misc queries) 3 December 19th 05 12:46 PM
Simple code crashes Excel John[_60_] Excel Programming 1 October 27th 04 05:59 PM
Releasing all Userforms in memory Rich[_24_] Excel Programming 1 August 25th 04 02:56 PM
VB6 with Excel Objects: Please review my code Kurt Remlin Excel Programming 6 May 1st 04 03:36 AM
Question about releasing memory TBA[_2_] Excel Programming 2 January 20th 04 04:24 AM


All times are GMT +1. The time now is 12:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"