SwxCleanupActivity Activity

Purpose: This activity clears SolidWorks COM object references cached in the SwxDocumentService. Place this activity at the end of workflows that use SolidWorks documents to free up memory and prevent resource leaks. It clears the in-memory dictionaries that track open documents.

Input Properties

ForceCleanup

Force cleanup even when many documents are tracked. By default, the activity has a safety guard that prevents cleanup when more than 20 documents are tracked unless this is set to true.

Type: bool

Default: false

Note: Set to true to override the safety check and clean up all tracked documents regardless of count.

Output Properties

Success

Indicates whether cleanup ran successfully.

Type: bool

Note: Returns false if the safety check blocked cleanup (more than 20 documents and ForceCleanup is false).

DocumentsCleared

Number of documents that were cleared from the cache.

Type: int

Note: Will be 0 if no documents were tracked, or if cleanup was blocked by the safety check.

StatusMessage

Cleanup status message providing details about the operation.

Type: string

Note: Contains information about the cleanup operation, including why it may have been blocked.

Usage Example

Scenario: Clean up SolidWorks document references at the end of a workflow

Configuration:
- ForceCleanup: false (default)

Result:
- Success: true
- DocumentsCleared: 5
- StatusMessage: "Cleared 5 COM object references."

Scenario: Force cleanup when many documents are tracked

Configuration:
- ForceCleanup: true

Result:
- Success: true
- DocumentsCleared: 25
- StatusMessage: "Cleared 25 COM object references."

Error Handling

Important: The activity includes a safety guard:

  • If more than 20 documents are tracked and ForceCleanup is false, cleanup will be blocked
  • When blocked, Success will be false, DocumentsCleared will be 0, and StatusMessage will explain why cleanup was blocked
  • Set ForceCleanup to true to override the safety check
  • If no documents are tracked, cleanup will succeed with 0 documents cleared

Use ForceCleanup carefully - only set it to true when you're certain you want to clear all tracked documents.

Important Notes

  • Place this activity at the end of workflows that use SolidWorks documents to prevent memory leaks
  • This activity only clears the in-memory dictionaries - it does not close documents in SolidWorks
  • The safety guard (20 document limit) helps prevent accidental mass-cleanup
  • After cleanup, document IDs from previous operations will no longer be valid
  • This is a maintenance activity - use it to free up resources after completing SolidWorks operations
  • If you need to continue working with documents after cleanup, you'll need to reopen them

Related Activities