Merge lp:~zorba-coders/zorba/bug935639 into lp:zorba

Proposed by Rodolfo Ochoa
Status: Merged
Approved by: Rodolfo Ochoa
Approved revision: 10692
Merged at revision: 10717
Proposed branch: lp:~zorba-coders/zorba/bug935639
Merge into: lp:zorba
Diff against target: 274 lines (+165/-7)
9 files modified
doc/zorba/indexpage.dox.in (+2/-0)
doc/zorba/memory_leaks.dox (+141/-0)
include/zorba/pregenerated/diagnostic_list.h (+2/-0)
modules/com/zorba-xquery/www/modules/pregenerated/errors.xq (+4/-0)
src/diagnostics/diagnostic_en.xml (+4/-0)
src/diagnostics/pregenerated/diagnostic_list.cpp (+3/-0)
src/diagnostics/pregenerated/dict_en.cpp (+1/-0)
src/store/naive/node_items.cpp (+1/-1)
src/store/naive/string_pool.cpp (+7/-6)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug935639
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Markos Zaharioudakis Approve
Cezar Andrei Approve
Review via email: mp+94900@code.launchpad.net

Commit message

This fixes the error:
n strings remain in the pool.
and change it to a more comprehensive error with reference to document that helps to prevent the error.

Description of the change

The problem can't be solved by technical means, the developer have to take care of resource usage, as in C++ the user must release all objects before shutdown the store, the same thing applies for XQJ.
So. the best workaround this problem is to show a more friendly message around the Strings Pool and create documentation that explain this issue. At the end, this issue affects every API usage from our clients.
Please check my changes and help me with English usage in the new document I created.

To post a comment you must log in.
Revision history for this message
Cezar Andrei (cezar-andrei) :
review: Approve
Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

The Zorba XQuery Processor manage => The Zorba XQuery Processor manages

automaticall => automatically

review: Needs Fixing
Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug935639 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:274 (message):
  Validation queue job bug935639-2012-03-07T22-33-06.388Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug935639 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:274 (message):
  Validation queue job bug935639-2012-03-11T01-05-09.922Z is finished. The
  final status was:

  3 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug935639 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:274 (message):
  Validation queue job bug935639-2012-03-12T01-12-03.818Z is finished. The
  final status was:

  1 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

lp:~zorba-coders/zorba/bug935639 updated
10691. By Rodolfo Ochoa

fix for errors.xq in CTESTs

10692. By Rodolfo Ochoa

bug from the editor

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug935639-2012-03-12T23-14-08.66Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'doc/zorba/indexpage.dox.in'
--- doc/zorba/indexpage.dox.in 2012-03-07 17:13:34 +0000
+++ doc/zorba/indexpage.dox.in 2012-03-12 23:11:19 +0000
@@ -28,6 +28,8 @@
28 - \ref ft_intro28 - \ref ft_intro
29 - \ref errors_warnings29 - \ref errors_warnings
30 - \ref impl_dep_features30 - \ref impl_dep_features
31 - \ref memory_management
32 - \ref memory_leaks
3133
32\section xqlib XQuery Modules34\section xqlib XQuery Modules
33 - <a href="../xqdoc/xhtml/index.html">XQuery Module Library</a>35 - <a href="../xqdoc/xhtml/index.html">XQuery Module Library</a>
3436
=== added file 'doc/zorba/memory_leaks.dox'
--- doc/zorba/memory_leaks.dox 1970-01-01 00:00:00 +0000
+++ doc/zorba/memory_leaks.dox 2012-03-12 23:11:19 +0000
@@ -0,0 +1,141 @@
1/** \page memory_leaks Memory Leaks
2
3\section memory_leaks_intro Introduction
4
5The Zorba XQuery Processor manages automatically its own memory, but still, there are cases where you may receive the following message:
6
7\code
8Zorba did not close properly, objects may still in memory while shutdown the store.
9[n] referenced URIs remain in the string pool.
10For help avoiding this message please refer to http://www.zorba-xquery.com/html/documentation in section General Architecture -> Memory Leaks.
11\endcode
12
13This message means that not all the resources (e.g. XQuery objects)
14were released before Zorba and its store were shutdown.
15While this might be a bug/memory leak in Zorba itself, it's also quite likely that the leak is in the application.
16For the application, the rule is that before shutting down the store
17all resources must have been released.
18
19So, strictly speaking, your program is leaking resources.
20
21This problem might occur even though the application's code (C++ or other languages) looks good. Here is an example:
22
23\section memory_leaks_example_c Example in C++
24In the following example, the StaticContext and XQuery objects are not destroyed before Zorba and the store are shutdown.
25
26\code
27int main(int argc, char* argv[])
28{
29 void* lStore = zorba::StoreManager::getStore();
30 Zorba* lZorba = Zorba::getInstance(lStore);
31
32 StaticContext_t lContext = lZorba->createStaticContext();
33 lContext->addNamespace("foo", "http://www.foo.com");
34 XQuery_t lQuery = lZorba->compileQuery("<foo:e/>", lContext);
35 lQuery->execute();
36
37 lZorba->shutdown();
38 zorba::StoreManager::shutdownStore(lStore);
39 return 0;
40}
41\endcode
42
43So, for this scenario, the ideal way to solve the problem is through scopes,
44where you implement certain part of code in methods and release them when the objects loose their reference.
45Alternatively, you can explicitly set the variable to null, in which case the object will automatically be released.
46
47Solution example:
48\code
49int main(int argc, char* argv[])
50{
51 void* lStore = zorba::StoreManager::getStore();
52 Zorba* lZorba = Zorba::getInstance(lStore);
53
54 { // Use a scope
55
56 StaticContext_t lContext = lZorba->createStaticContext();
57 lContext->addNamespace("foo", "http://www.foo.com");
58 XQuery_t lQuery = lZorba->compileQuery("<foo:e/>", lContext);
59 lQuery->execute();
60
61 lContext = NULL; // or explicitely set free the resources
62 lQuery = NULL;
63 }
64 lZorba->shutdown();
65 zorba::StoreManager::shutdownStore(lStore);
66 return 0;
67}
68\endcode
69
70
71\section memory_leaks_example_java Example in Java
72This particular error is specially notorious when a memory managed language
73shows the error because you expect the language frees all memory, here is an example:
74
75\code
76public static void main ( String argv[] )
77{
78 InMemoryStore store = InMemoryStore.getInstance();
79 Zorba zorba = Zorba.getInstance ( store );
80
81 StaticContext context = zorba.createStaticContext();
82 context.addNamespace("foo", "http://www.foo.com");
83 XQuery query = zorba.compileQuery("<foo:e/>", context);
84 String result = query.execute();
85
86 zorba.shutdown();
87 InMemoryStore.shutdown ( store );
88
89}
90\endcode
91
92In this example, and for the rest of the languages because Zorba is created in C++,
93we have created in the Zorba API the method \c destroy() \e that will set free the object
94that could be pointing to any resource from the store, this method is in every object that need to be released.
95
96*Java Note: Because Java is a garbage collected language you cannot predict when (or even if) an object will be destroyed.
97Hence there is no direct equivalent of a destructor.
98There is an inherited method called finalize, but this is called entirely at the discretion of the garbage collector.
99So, destroy() is the best practice for any language including Java.
100
101Solution example:
102\code
103public static void main ( String argv[] )
104{
105 InMemoryStore store = InMemoryStore.getInstance();
106 Zorba zorba = Zorba.getInstance ( store );
107
108 StaticContext context = zorba.createStaticContext();
109 context.addNamespace("foo", "http://www.foo.com");
110 XQuery query = zorba.compileQuery("<foo:e/>", context);
111 String result = query.execute();
112
113 query.destroy(); // Release memory for this XQuery
114 context.destroy(); // Release memory for this StaticContext
115
116 zorba.shutdown();
117 InMemoryStore.shutdown ( store );
118
119}
120\endcode
121
122
123\section memory_leaks_example_xqj Example in XQJ
124
125XQJ standard provides specific \c close() \e methods for this specific purpose:
126\code
127 XQDataSource xqdatasource = new XQDataSource();
128 XQConnection xqconnection = xqdatasource.getConnection();
129 XQStaticContext staticContext = xqconnection.getStaticContext();
130 staticContext.declareNamespace("foo", "http://www.foo.com");
131 xqconnection.setStaticContext(staticContext);
132 XQExpression xqexpression = xqconnection.createExpression();
133 XQSequence xqsequence = xqexpression.executeQuery("<foo:e/>");
134 // code to show the output
135
136 xqconnection.close(); // Closing connection frees all related resources
137\endcode
138
139
140*/
141/* vim:set et sw=2 ts=2: */
0142
=== modified file 'include/zorba/pregenerated/diagnostic_list.h'
--- include/zorba/pregenerated/diagnostic_list.h 2012-03-08 18:51:25 +0000
+++ include/zorba/pregenerated/diagnostic_list.h 2012-03-12 23:11:19 +0000
@@ -734,6 +734,8 @@
734734
735extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZSTR0060_RANGE_EXCEPTION;735extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZSTR0060_RANGE_EXCEPTION;
736736
737extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZSTR0065_STRINGS_IN_POOL;
738
737extern ZORBA_DLL_PUBLIC ZorbaErrorCode XSST0001;739extern ZORBA_DLL_PUBLIC ZorbaErrorCode XSST0001;
738740
739extern ZORBA_DLL_PUBLIC ZorbaErrorCode XSST0002;741extern ZORBA_DLL_PUBLIC ZorbaErrorCode XSST0002;
740742
=== modified file 'modules/com/zorba-xquery/www/modules/pregenerated/errors.xq'
--- modules/com/zorba-xquery/www/modules/pregenerated/errors.xq 2012-03-08 18:51:25 +0000
+++ modules/com/zorba-xquery/www/modules/pregenerated/errors.xq 2012-03-12 23:11:19 +0000
@@ -764,6 +764,10 @@
764764
765(:~765(:~
766:)766:)
767declare variable $zerr:ZSTR0065 as xs:QName := fn:QName($zerr:NS, "zerr:ZSTR0065");
768
769(:~
770:)
767declare variable $zerr:XSST0001 as xs:QName := fn:QName($zerr:NS, "zerr:XSST0001");771declare variable $zerr:XSST0001 as xs:QName := fn:QName($zerr:NS, "zerr:XSST0001");
768772
769(:~773(:~
770774
=== modified file 'src/diagnostics/diagnostic_en.xml'
--- src/diagnostics/diagnostic_en.xml 2012-03-08 18:51:25 +0000
+++ src/diagnostics/diagnostic_en.xml 2012-03-12 23:11:19 +0000
@@ -2334,6 +2334,10 @@
2334 <value>out of range: $1</value>2334 <value>out of range: $1</value>
2335 </diagnostic>2335 </diagnostic>
23362336
2337 <diagnostic code="ZSTR0065" name="STRINGS_IN_POOL">
2338 <value>Zorba did not close properly, objects may still in memory.\n$1 referenced URI(s) remain in the string pool.\nFor help avoiding this message please refer to http://www.zorba-xquery.com/html/documentation in section General Architecture -> Memory Leaks.</value>
2339 </diagnostic>
2340
2337 <!--////////// XQuery Scripting ////////////////////////////////////////-->2341 <!--////////// XQuery Scripting ////////////////////////////////////////-->
23382342
2339 <diagnostic code="XSST0001">2343 <diagnostic code="XSST0001">
23402344
=== modified file 'src/diagnostics/pregenerated/diagnostic_list.cpp'
--- src/diagnostics/pregenerated/diagnostic_list.cpp 2012-03-08 18:51:25 +0000
+++ src/diagnostics/pregenerated/diagnostic_list.cpp 2012-03-12 23:11:19 +0000
@@ -1079,6 +1079,9 @@
1079ZorbaErrorCode ZSTR0060_RANGE_EXCEPTION( "ZSTR0060" );1079ZorbaErrorCode ZSTR0060_RANGE_EXCEPTION( "ZSTR0060" );
10801080
10811081
1082ZorbaErrorCode ZSTR0065_STRINGS_IN_POOL( "ZSTR0065" );
1083
1084
1082ZorbaErrorCode XSST0001( "XSST0001" );1085ZorbaErrorCode XSST0001( "XSST0001" );
10831086
10841087
10851088
=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
--- src/diagnostics/pregenerated/dict_en.cpp 2012-03-08 18:51:25 +0000
+++ src/diagnostics/pregenerated/dict_en.cpp 2012-03-12 23:11:19 +0000
@@ -378,6 +378,7 @@
378 { "ZSTR0050", "\"$1\" not implemented for item type \"$2\"" },378 { "ZSTR0050", "\"$1\" not implemented for item type \"$2\"" },
379 { "ZSTR0055", "streamable string has already been consumed" },379 { "ZSTR0055", "streamable string has already been consumed" },
380 { "ZSTR0060", "out of range: $1" },380 { "ZSTR0060", "out of range: $1" },
381 { "ZSTR0065", "Zorba did not close properly, objects may still in memory.\n$1 referenced URI(s) remain in the string pool.\nFor help avoiding this message please refer to http://www.zorba-xquery.com/html/documentation in section General Architecture -> Memory Leaks." },
381 { "ZWST0002", "\"$1\": unknown or unsupported annotation" },382 { "ZWST0002", "\"$1\": unknown or unsupported annotation" },
382 { "ZWST0003", "\"$1\": function declared sequential, but has non-sequential body" },383 { "ZWST0003", "\"$1\": function declared sequential, but has non-sequential body" },
383 { "ZWST0004", "Sequential FLWOR expr may not have the semantics you expect" },384 { "ZWST0004", "Sequential FLWOR expr may not have the semantics you expect" },
384385
=== modified file 'src/store/naive/node_items.cpp'
--- src/store/naive/node_items.cpp 2012-03-07 14:22:29 +0000
+++ src/store/naive/node_items.cpp 2012-03-12 23:11:19 +0000
@@ -722,7 +722,7 @@
722 }722 }
723 catch (...)723 catch (...)
724 {724 {
725 ZORBA_FATAL(false, "Unexpectd exception");725 ZORBA_FATAL(false, "Unexpected exception");
726 }726 }
727}727}
728728
729729
=== modified file 'src/store/naive/string_pool.cpp'
--- src/store/naive/string_pool.cpp 2012-02-15 10:25:02 +0000
+++ src/store/naive/string_pool.cpp 2012-03-12 23:11:19 +0000
@@ -15,9 +15,10 @@
15 */15 */
16#include "stdafx.h"16#include "stdafx.h"
1717
18#include "zorbautils/fatal.h"
19#include "util/string_util.h"18#include "util/string_util.h"
20#include "string_pool.h"19#include "string_pool.h"
20#include "zorba/zorba_exception.h"
21#include "diagnostics/xquery_diagnostics.h"
2122
22namespace zorba { namespace simplestore {23namespace zorba { namespace simplestore {
2324
@@ -32,14 +33,14 @@
32 {33 {
33 if (theHashTab[i].theItem.is_shared())34 if (theHashTab[i].theItem.is_shared())
34 {35 {
35 std::cerr << "i = " << i << " String " << theHashTab[i].theItem36 //std::cerr << "ID: " << i << " Referenced URI: " << theHashTab[i].theItem << std::endl;
36 << " is still in the pool" << std::endl;
37 //delete theHashTab[i].theString.getp();37 //delete theHashTab[i].theString.getp();
38 count++;38 count ++;
39 }39 }
40 }40 }
4141 if (count>0) {
42 ZORBA_FATAL(count == 0, count << " strings remain in the string pool");42 throw ZORBA_EXCEPTION(zerr::ZSTR0065_STRINGS_IN_POOL, ERROR_PARAMS(count));
43 }
43}44}
4445
4546

Subscribers

People subscribed via source and target branches