Our problem is basically that memory that is allocated when a report is opened in our product stays allocated, even when the report is closed again. If several reports are opened and closed in succession, the memory in use rises rapidly, to the point where a SystemOutOfMemory-exception is raised and our product no longer functions. The issue is definitely with the reports, since the amount of memory that is used up varies with different reports.
We store our reports directly in our database, as memo fields. If a report is opened, it is created like this:
StiReport actRpt = new StiReport();
byte[] buffer = rptTable.Rows[0][Fld.RPTSOURCE] as byte[];
actRpt.Load(buffer);
Later on, the report gets its data more or less like this:
QueryInfos infos = new QueryInfos();
foreach (StiDataSource dataSource in actRpt.Dictionary.DataSources)
{
StiSqlSource source = dataSource as StiSqlSource;
string sql = source.SqlCommand;
infos.Add(dataSource.Name, sql, parameter);
}
DataSet ds = globalParameter.DataProvider.LoadQueries(infos);
foreach (StiDataSource dataSource in actRpt.Dictionary.DataSources)
{
string tableName = dataSource.Name;
QueryData dataS = new QueryData();
dataS.name = tableName;
dataS.dt = ds.Tables[tableName];
dataSources.Add(dataS);
}
StiDataRelationsCollection relationsCollection = new StiDataRelationsCollection(actRpt.Dictionary);
foreach (StiDataRelation rel in actRpt.Dictionary.Relations)
{
relationsCollection.Add(rel);
}
actRpt.DataSources.Clear();
actRpt.Dictionary.Databases.Clear();
foreach (QueryData dataS in dataSources)
{
actRpt.RegData(dataS.name, dataS.dt);
}
actRpt.Dictionary.Synchronize();
for (int i = 0; i < actRpt.DataSources.Count; i++)
{
actRpt.Dictionary.DataSources.Name = dataSources.name;
}
foreach (StiDataRelation rel in relationsCollection)
{
rel.NameInSource = rel.Name;
actRpt.Dictionary.Relations.Add(rel);
}
Then the report is rendered:
actRpt.Render(globalParameter.ShowProgressWindow);
It is then handed over to a ReportViewer:
rptViewer.Report = actRpt;
The viewer is then displayed in our product. On closing the viewer, no specific action is taken.
We did inspect memory use before and after closing the ReportViewer using a memory profiler. As far as we can see, there are no surviving instances of StiReport after closing the Viewer. But still, the memory is not freed up.
We would very much appreciate any help you can give us with this problem.