So as a VB programmer I've had the maxim of "always set your objects to Nothing" beaten into me. But another programmer and I were talking at work, and the idea hit both of us: What about running VB components under COM+? Wouldn't COM+ know when an object reference went out of scope?
So I ran me some tests. I made two simple classes. Class1's Test function instantiates an object, then exits. Class2's Test function instantiates an object, sets it to Nothing on the next line, then exits. I compiled both of these classes into DLLs and registered them in different COM+ applications. (This is on Win2K Pro.)
To run the COM+ applications, I used an ASP client that instantiated Class1 and Class2, then used a For loop to call both classes' Test methods 100 times.
As I expected, two new instances of DLLHOST.EXE began running, one for each of Class1 and Class2. They were both taking up about the same amount of memory.
I ran my ASP page a couple more times, and both instances of DLLHOST used a bit more memory, but eventually hit a memory usage plateau. The two instances were still using almost exactly the same amount of memory.
Then I let the application sit, idle. Both instances of DLLHOST started to decrease in memory usage, about 4~8KB every minute or two. Again, both instances were very close to each other in memory usage, and seemed to be releasing memory at roughly the same rate.
In short:
The application where object references weren't being set to Nothing wasn't using more memory than the application where object references were set to Nothing.
So... is there something wrong with my (admittedly rough) testing procedures, or do I not need to clutter up VB code that will run under COM+ with innumerable Set <object> = Nothing calls?
Q
So I ran me some tests. I made two simple classes. Class1's Test function instantiates an object, then exits. Class2's Test function instantiates an object, sets it to Nothing on the next line, then exits. I compiled both of these classes into DLLs and registered them in different COM+ applications. (This is on Win2K Pro.)
To run the COM+ applications, I used an ASP client that instantiated Class1 and Class2, then used a For loop to call both classes' Test methods 100 times.
As I expected, two new instances of DLLHOST.EXE began running, one for each of Class1 and Class2. They were both taking up about the same amount of memory.
I ran my ASP page a couple more times, and both instances of DLLHOST used a bit more memory, but eventually hit a memory usage plateau. The two instances were still using almost exactly the same amount of memory.
Then I let the application sit, idle. Both instances of DLLHOST started to decrease in memory usage, about 4~8KB every minute or two. Again, both instances were very close to each other in memory usage, and seemed to be releasing memory at roughly the same rate.
In short:
The application where object references weren't being set to Nothing wasn't using more memory than the application where object references were set to Nothing.
So... is there something wrong with my (admittedly rough) testing procedures, or do I not need to clutter up VB code that will run under COM+ with innumerable Set <object> = Nothing calls?
Q