Hello, my question is about a c# on .net 2.0 application that I'm building. I am creating an encyclopedia-like area within the application that holds information about plants. I've created a few classes for this area that represent different sets of plant information. Whenever I try to view the details of a plant I'm getting the exception System.OutOfMemoryException and I am having trouble figuring out why. I am using many arrays all at once. Is it too much for .net to handle? Can anyone point me toward a more efficient way of coding this? Here's the portion of offending code:
Thanks,
Joe Dulany
protected void PrintPlantAttributes(plant p)
{
ArrayList items = new ArrayList();
if (p.height.Length > 0)
{
PlantAttribute paHeight = new PlantAttribute();
paHeight.AttributeName =
"Height:";
paHeight.AttributeList = p.height.Split(
new char[] { ',' });
items.Add(paHeight);
}
if (p.spread.Length > 0)
{
PlantAttribute paSpread = new PlantAttribute();
paSpread.AttributeName =
"Spread:";
paSpread.AttributeList = p.spread.Split(
new char[] { ',' });
items.Add(paSpread);
}
if (p.growthRate.Length > 0)
{
PlantAttribute paGrowthRate = new PlantAttribute();
paGrowthRate.AttributeName =
"Growth Rate:";
paGrowthRate.AttributeList = p.growthRate.Split(
new char[] { ',' });
items.Add(paGrowthRate);
}
if (p.bloomSeason.Length > 0)
{
PlantAttribute paBloomSeason = new PlantAttribute();
paBloomSeason.AttributeName =
"Bloom Season:";
paBloomSeason.AttributeList = p.bloomSeason.Split(
new char[] { ',' });
items.Add(paBloomSeason);
}
if (p.bloomColor.Length > 0)
{
PlantAttribute paBloomColor = new PlantAttribute();
paBloomColor.AttributeName =
"Bloom Color:";
paBloomColor.AttributeList = p.bloomColor.Split(
new char[] { ',' });
items.Add(paBloomColor);
}
if (p.hardiness.Length > 0)
{
PlantAttribute paHardiness = new PlantAttribute();
paHardiness.AttributeName =
"Hardiness:";
paHardiness.AttributeList = p.hardiness.Split(
new char[] { ',' });
items.Add(paHardiness);
}
if (p.soilType.Length > 0)
{
PlantAttribute paSoilType = new PlantAttribute();
paSoilType.AttributeName =
"Soil:";
paSoilType.AttributeList = p.soilType.Split(
new char[] { ',' });
items.Add(paSoilType);
}
if (p.exposure.Length > 0)
{
PlantAttribute paExposure = new PlantAttribute();
paExposure.AttributeName =
"Light Needs:";
paExposure.AttributeList = p.exposure.Split(
new char[] { ',' });
items.Add(paExposure);
}
if (p.attracts.Length > 0)
{
PlantAttribute paAttracts = new PlantAttribute();
paAttracts.AttributeName =
"Attracts:";
paAttracts.AttributeList = p.attracts.Split(
new char[] { ',' });
items.Add(paAttracts);
}
if (p.resists.Length > 0)
{
PlantAttribute paResists = new PlantAttribute();
paResists.AttributeName =
"Resists:";
paResists.AttributeList = p.resists.Split(
new char[] { ',' });
items.Add(paResists);
}
if (p.attributes.Length > 0)
{
PlantAttribute paAttributes = new PlantAttribute();
paAttributes.AttributeName =
"Other Attributes:";
paAttributes.AttributeList = p.attributes.Split(
new char[] { ',' });
items.Add(paAttributes);
}
StringBuilder writer = new StringBuilder();
int itemsCount = items.Count;
if (itemsCount > 0)
{
pnl_Characteristics.Visible =
true;
}
foreach (PlantAttribute pa in items)
{
for (int i = 0; i < 4; i++)
{
int x = 1;
if (i == 0)
{ writer.Append(
"<tr>"); }
writer.Append(
"<td valign=\"top\"><b>" + pa.AttributeName + "<ul>");
foreach (String str in pa.AttributeList)
{ writer.Append(
"<li>" + str.ToString().Trim() + "</li>"); }
writer.Append(
"</ul></td>");
if (i == 3 || x == itemsCount)
{
writer.Append(
"</tr>");
i = 0;
}
x++;
}
}