Expensive unused object
Description
This defect occurs when you construct an expensive local object using its default constructor but do not use the object. The list of objects that Polyspace® considers expensive includes:
Standard containers such as
std::vector
,std::list
,std::stack
,std::queue
,std::deque
,std::set
,std::map
,std::unordered_ser
, andstd::unorder_map
String classes such as
basic_string
andbasic_stringstream
Polyspace considers a local object to be unused if both of these conditions are true:
The object is either not initialized or initialized with constant data.
Your code does not read the object after construction.
Polyspace assumes that the default constructors of these objects have no side effects. Polyspace does not report this defect if you construct an expensive object using a user-defined constructor, which can have side effects.
Risk
Constructing and destroying expensive objects reduces the efficiency of your code. Compilers generally do not detect if constructed objects remain unused. Such expensive unused objects make your code unnecessarily inefficient.
Fix
To fix this defect, review your code. Either revise your code so that the expensive unused object is used, or remove its declaration.
Performance improvements might vary based on the compiler, library implementation, and environment that you are using.
Examples
Result Information
Group: Performance |
Language: C++ |
Default: Off |
Command-Line Syntax:
EXPENSIVE_UNUSED_OBJECT
|
Impact: Low |
Version History
Introduced in R2024a
See Also
Find defects
(-checkers)
| Expensive pass by
value
| Expensive return by
value
| Expensive copy in a range-based
for loop iteration
| Expensive local variable
copy
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)