# How to check if an object already created in uvm\_factory

**URL:** <https://verificationacademy.com/forums/t/how-to-check-if-an-object-already-created-in-uvm-factory/34614>\
**Category:** UVM\
**Tags:** UVM, confiburation-factory-visibility, Bind-Factory-UVM, uvm\_factory, factory-registration\
**Created:** [June 26, 2018, 3:15am UTC](https://verificationacademy.com/forums/t/how-to-check-if-an-object-already-created-in-uvm-factory/34614 "2018-06-26T03:15:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterjin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/f05b48/32.png) [@peterjin](https://verificationacademy.com/forums/u/peterjin)\
**Post date:** [June 26, 2018, 3:15am UTC](https://verificationacademy.com/forums/t/how-to-check-if-an-object-already-created-in-uvm-factory/34614/1 "2018-06-26T03:15:07Z")

</div>

Hi,

I wonder if there is a way to check if a certain object is already created and registered in uvm\_factory? If not, will there be a fatal error if I create a object multiple times?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [June 26, 2018, 2:43pm UTC](https://verificationacademy.com/forums/t/how-to-check-if-an-object-already-created-in-uvm-factory/34614/2 "2018-06-26T14:43:09Z")

</div>

_In reply to [peterjin](https://verificationacademy.com/forums/t/how-to-check-if-an-object-already-created-in-uvm-factory/34614):_

Registration with the factory and construction of an object are two different activities.

Regisration with the factory happens as part of static variable initialization before any initial block processes start. You will get an error if you try to register two classes with the same name, which can happen if you declare classes with the same name in two different packages. You get a compiler error if you try to reference a class by type with the factory, but it has not been registered. You can also use the debug\_create\_by\_type/name methods in the UVM factory.

There is nothing built-in to SystemVerilog or UVM that tells you if a particular class type has every been constructed, though simulation debugging tools may give you this information.

If you want to make sure a class only gets constructed once, use the _[singleton](https://verificationacademy.com/forums/systemverilog/proxy-class-and-singleton-class)_ design pattern.

---

<div class="post-metadata">

**Author:** ![peterjin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/f05b48/32.png) [@peterjin](https://verificationacademy.com/forums/u/peterjin)\
**Post date:** [June 28, 2018, 11:28pm UTC](https://verificationacademy.com/forums/t/how-to-check-if-an-object-already-created-in-uvm-factory/34614/3 "2018-06-28T23:28:25Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/how-to-check-if-an-object-already-created-in-uvm-factory/34614/2):_

Thanks for the explanation!

Hao
