G
Guest
We have a C# app that runs on the PocketPC. We are having some odd behavior
reported from our users that I have been unable to recreate. It made me
start to look at memory issues. One of the appl errors that they get can
only come up when a static member variable inside a class is set to NULL.
The setting of that value is pretty controlled and I don't believe that the
value is changing to NULL through normal logic flow.
the class itself is not defined as static but all the access methods and
member variables are. Is there any situation where garbage collecting could
kick in and reset the memory inside the object. I don't actually ever
declare an instance of the class itself. Below is an abbreviated version of
the class definition:
namespace MobileTest
{
public class gDataMgr
{
public gDataMgr()
{
}
public static Staff CurrentStaff
{
get{ return m_CurrentStaff; }
}
public static long FacilityID
{
get{ return m_CMSFacilityID; }
set{ m_CMSFacilityID = value; }
}
public static ArrayList ActiveTimeList
{
get
{
if (m_ActiveTimeList == null)
{
m_ActiveTimeList = new ArrayList();
}
return m_ActiveTimeList;
}
set{ m_ActiveTimeList = value; }
}
public static bool Login(Staff staff)
{
m_CurrentStaff = staff;
}
private static Staff m_CurrentStaff;
private static long m_CMSFacilityID = 1;
private static ArrayList m_ActiveTimeList;
}
}
The m_CurrentStaff gets assigned by calling the Login method in this class.
The Staff does not get set to NULL until the user logs out.
This is the code that prints the app error message:
// inside some app logic
Staff currentStaff = gDataMgr.CurrentStaff;
if (currentStaff != null)
{
sDiscipline = currentStaff.StaffType;
}
else
{
MessageBox.Show("LOGIC ERROR: Unable to retrieve the current staff .");
return null;
}
Thanks for any assistance with this.
Regards,
-Rob C
reported from our users that I have been unable to recreate. It made me
start to look at memory issues. One of the appl errors that they get can
only come up when a static member variable inside a class is set to NULL.
The setting of that value is pretty controlled and I don't believe that the
value is changing to NULL through normal logic flow.
the class itself is not defined as static but all the access methods and
member variables are. Is there any situation where garbage collecting could
kick in and reset the memory inside the object. I don't actually ever
declare an instance of the class itself. Below is an abbreviated version of
the class definition:
namespace MobileTest
{
public class gDataMgr
{
public gDataMgr()
{
}
public static Staff CurrentStaff
{
get{ return m_CurrentStaff; }
}
public static long FacilityID
{
get{ return m_CMSFacilityID; }
set{ m_CMSFacilityID = value; }
}
public static ArrayList ActiveTimeList
{
get
{
if (m_ActiveTimeList == null)
{
m_ActiveTimeList = new ArrayList();
}
return m_ActiveTimeList;
}
set{ m_ActiveTimeList = value; }
}
public static bool Login(Staff staff)
{
m_CurrentStaff = staff;
}
private static Staff m_CurrentStaff;
private static long m_CMSFacilityID = 1;
private static ArrayList m_ActiveTimeList;
}
}
The m_CurrentStaff gets assigned by calling the Login method in this class.
The Staff does not get set to NULL until the user logs out.
This is the code that prints the app error message:
// inside some app logic
Staff currentStaff = gDataMgr.CurrentStaff;
if (currentStaff != null)
{
sDiscipline = currentStaff.StaffType;
}
else
{
MessageBox.Show("LOGIC ERROR: Unable to retrieve the current staff .");
return null;
}
Thanks for any assistance with this.
Regards,
-Rob C