Create a Pooled Component

Problem

You want to use COM+ object pooling to maintain a pool of preinitialized objects.

Solution

Derive your class from ServicedComponent, add the ObjectPooling attribute, and override the CanBePooled method.

Discussion

With object pooling, a "pool" of available, instantiated objects is retained permanently. When a client creates an object, COM+ provides a preinitialized object from the pool. When a client releases an object, it isn’t destroyed, but is instead returned to the object pool, where it remains ready to serve another client. Object pooling is most often used for one of two reasons in a distributed application:

  • To reduce the cost of creating an expensive object. Most objects can be created quite quickly and easily. ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.