Missing object

  • Thread starter Thread starter Jerry
  • Start date Start date
J

Jerry

I have an object which uses a class from a dll.

the dll is XTAPI.dll

I have a class

public class a
{
public XTAPI.b xb = null;
public XTAPI.c xc = null;
public string temp = "";

public a()
{
xb = new XTAPI.b();
xc = new XTAPI.c();
temp = "new string";
}

...
}

and another class

public class d
{
...
}

I have a form that initiliaze class a in the form_load function.

when my event handler is called to process an event from class d I
need to use class a to perform certain functions. The problem is that
my class a seems to have lost access to xb and xc (I think the garbage
collector took it)

I didnt want to recreate class a everything in the event handler
because it has certain overhead which I want to reduce to only
performing once hence why I tried to initiliaze it in the form_load
function of the form.

Can anyone tell me why or how to fix my code so that I am able to see
my objects in class a?.

p.s as an added note I can see the string in class a but I get an
error: cannot obtain value when I am in the event handler for class d
when I try to look into the object xb and xc of class a.

thanks
 
Jerry,

The GC doesn't take anything that a reference exists for. If the class
dissapears, then it is because all references to it have been released, and
it is not in use anymore.

If you have an instance of a, then the only way that xb and xc are null
(assuming that is the only constructor) is if they are explictly set to null
by a piece of code.

You are probably setting those fields to null somewhere, and don't know
it.

Hope this helps.
 
Back
Top