/doc/variant.objrefs.html
HTML | 39 lines | 35 code | 0 blank | 4 comment | 0 complexity | 94df9c4f35a7011e24cf0a57169777ba MD5 | raw file
1<html><!-- #BeginTemplate "/Templates/tmpl.dwt" --><!-- DW6 --> 2<head> 3<!-- #BeginEditable "doctitle" --> 4<title>PTypes: variant: object references</title> 5<!-- #EndEditable --> 6<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 7<link rel="stylesheet" href="styles.css"> 8</head> 9<body bgcolor="#FFFFFF" leftmargin="40" marginwidth="40"> 10<p><a href="../index.html"><img src="title-21.png" width="253" height="39" alt="C++ Portable Types Library (PTypes) Version 2.1" border="0"></a> 11<hr size="1" noshade> 12<!-- #BeginEditable "body" --> 13<p class="hpath"><a href="index.html">Top</a>: <a href="basic.html">Basic types</a>: 14<a href="variant.html">variant</a>: Object references</p> 15<p><br> 16Variants can hold references to objects derived from <span class="lang">component</span>. 17PTypes performs reference counting, so that assigning variants containing object 18references can be considered safe: an object will only be destroyed when there 19are no more references left to it. If you want to control the destruction of an 20object 'manually', you can increment the reference count with <span class="lang">addref()</span> 21before assigning a reference to a variant (see <a href="unknown.html">unknown 22& component</a>). In this case, each call to <span class="lang">addref()</span> 23should be balanced with a call to <span class="lang">release()</span>.</p> 24<p>It should be noted that the reference counting mechanism has a potential flaw 25which may lead to memory leaks. Consider two objects containing variants with 26cross-referencing pointers to each other. The library can not keep track of such 27circular references, and an attempt to free one of the objects will result in 28destroying only one of them and leaving the other in the memory without any references 29to it. This is a known problem and can be solved by either eliminating circular 30references when designing data structures or by providing a complex memory 'garbage 31collector' which keeps track of all object references in the program.</p> 32<p class="seealso">See also: <a href="unknown.html">unknown & component</a>, 33<a href="variant.typecasts.html">Assignments and typecasts</a>, <a href="variant.arrays.html">Arrays</a>, 34<a href="variant.utils.html">Utilities</a> </p> 35<!-- #EndEditable --> 36<hr size="1"> 37<a href="../index.html" class="ns">PTypes home</a> 38</body> 39<!-- #EndTemplate --></html>