A computer-assisted design program widely used to prepare drawings, plans, details, schematics, schedules, diagrams and other graphic illustrations. An example of
SoftwareEvolution, where each new version of the software improves the operation and usability to fit the users' needs. Produced by
AutoDesk and is currently in its 16th or 17th generation.
Most recent versions of
AutoCad are bundled with a
VisualLispIde (VLIDE) and
VisualBasicForApplications (VBAIDE).
An
AutoCad AntiPattern:
- add temporary AcadEntity
- use temporary AcadEntity
- delete temporary AcadEntity
Repeat for thousands of entities.
This will act like a
MemoryLeak:
AutoCad will create the entities, but it will not remove them from memory. Instead, it will mark them for deletion. The entities will stay in memory until the drawing closes, or until
AutoCad runs out of memory and fatal errors.
This is an
AntiPattern because it crashes
AutoCad, and causes the user to lose their work.
Indeed,
AutoCad creates as many database objects as needed. When those objects are deleted from the database, they are simply marked as deleted; they are not explicitly deallocated from memory.
However, each business object in the system is managed with the aid of a
TombStone called an
ObjectId. All references to business objects are held through their corresponding
ObjectIds. When a pointer to object is needed, the client must request the object to be opened.
AutoCad performs it own paging which is independent from the OS. The objects marked as deleted are the first to get paged to disk, leaving only their corresponding
TombStones behind.
The
TombStones also help
AutoCad better manage transactions and serialization.
The problem with the first approach is that
AutoCad assumes that every entity (except for Selection
Set
s) is a permanent business object.
AutoCad assumes that any changes to the entity might need to be undone later.
AutoCad does not understand that the deleted object was temporary, and that there is no need to retain it in memory.
A second approach, that is better in some situations:
- add temporary AcadEntity
- use temporary AcadEntity
- use "undo" "back" to undo the addition and use of the AcadEntity
A third approach, recommended by
AutoDesk for temporary selection sets:
- add temporary SelectionSet
- use temporary SelectionSet
- set the temporary SelectionSet to nil
This works (and is necessary) because Selection
Set
s are stored in a completely different way from Acad
Entity
s. Selection
Set
s are virtual files.
AutoCad can have only 128 Selection
Set
s open at a time. Trying to create a 129 Selection
Set results in a gentle failure. When a Selection
Set is set to nil, it goes back into the pool and can be reused.
While it is a good idea to avoid the first approach, there are times when it is the most straightforward way to write an
AutoCad macro. (For example, if a drawing needs to be compared to hundreds of images.)
One work-around is to have the macro pre-emptively close and re-open the drawing after every nth image, before
AutoCad uses up too much (virtual) memory and crashes.
Crashes Not with skilled use
In over 10 years of using
AutoCad to produce thousands of designs, I never had such problems. In that period of time, I cannot think of once where
AutoCad crashed in the process of creating, copying, moving or updating an entity. Not saying it cannot happen, but the skilled use of the product will result in good designs with increasingly more complex and reusable entitites, designs, menus and drawing packages. --
DonaldNoyes
CategorySuccess CategorySoftwareProduct