The framework deallocates the handle when you call the delete operator on the CDatabase object.
我用odbc打开一个CDatabase对象,虽然,退出前close了,还是有内存泄露,应该怎么删除对象呀
我的程序中用了两个全局变量的CDatabase对象分别连接本地和服务器上的数据库
4 个解决方案
#1
程序在联网的时候数据从服务器上读取,并存一部分在本地服务器
断网时从本地服务器上读取,并且会经常执行查询服务器数据来判断网络是否连接上
现在联网时程序退出不会又内存泄露,但是断网情况下登录就有内存泄露
Detected memory leaks!
Dumping objects ->
{941} normal block at 0x0A7038A0, 230 bytes long.
Data: < b j j > 14 62 85 00 6A 00 00 00 6A 00 00 00 01 00 00 00
{943} normal block at 0x0A7035E8, 122 bytes long.
Data: < b 4 4 > 14 62 85 00 34 00 00 00 34 00 00 00 01 00 00 00
f:\rtm\vctools\vc7libs\ship\atlmfc\src\mfc\dbcore.cpp(55) : {917} client block at 0x0A7051F0, subtype c0, 24 bytes long.
a CDBException object at $0A7051F0, 24 bytes long
{104} normal block at 0x00FA9A68, 230 bytes long.
Data: < b j j > 14 62 85 00 6A 00 00 00 6A 00 00 00 01 00 00 00
{106} normal block at 0x00FA9790, 122 bytes long.
Data: < b 4 4 > 14 62 85 00 34 00 00 00 34 00 00 00 01 00 00 00
f:\rtm\vctools\vc7libs\ship\atlmfc\src\mfc\dbcore.cpp(55) : {80} client block at 0x00FA9630, subtype c0, 24 bytes long.
上面的内存地址内容是下面这些
...b..............O.D.B.C.;.D.B.Q.=.d.:.\.d.e.s.i
.g.n. .p.r.o.j.e.c.t.\.Z.c.y.D.e.s.i.g.n.\.Z.c.y.
D.e.s.i.g.n.\.m.a.i.n...m.d.b.;.D.r.i.v.e.r.=.{.M
.i.c.r.o.s.o.f.t. .A.c.c.e.s.s. .D.r.i.v.e.r. .(.
*...m.d.b.).}.;.D.r.i.v.e.r.I.d.=.2.5.;.F.I.L.=.M
.S. .A.c.c.e.s.s.;.M.a.x.B.u.f.f.e.r.S.i.z.e.=.2.
0.4.8.;.P.a.g.e.T.i.m.e.o.u.t.=.5.;..............
.b..4...4.......O.R.A.-.1.2.5.6.0.:. .T.N.S.:. .O
S....M.hV........q..R.z.^.v .S.Q.L.S.e.t.C.o.n.n.
e.c.t.A.t.t.r. .1Y%..........................."..
.....h...p...................p........b..\...`...
....D.r.i.v.e.r.=.{.M.i.c.r.o.s.o.f.t. .A.c.c.e.s
.s. .D.r.i.v.e.r. .(.*...m.d.b.).}.;.D.b.q.=.d.:.
\.d.e.s.i.g.n. .p.r.o.j.e.c.t.\.Z.c.y.D.e.s.i.g.n
.\.Z.c.y.D.e.s.i.g.n.\.m.a.i.n...m.d.b.;.........
.........................."......................
断网时从本地服务器上读取,并且会经常执行查询服务器数据来判断网络是否连接上
现在联网时程序退出不会又内存泄露,但是断网情况下登录就有内存泄露
Detected memory leaks!
Dumping objects ->
{941} normal block at 0x0A7038A0, 230 bytes long.
Data: < b j j > 14 62 85 00 6A 00 00 00 6A 00 00 00 01 00 00 00
{943} normal block at 0x0A7035E8, 122 bytes long.
Data: < b 4 4 > 14 62 85 00 34 00 00 00 34 00 00 00 01 00 00 00
f:\rtm\vctools\vc7libs\ship\atlmfc\src\mfc\dbcore.cpp(55) : {917} client block at 0x0A7051F0, subtype c0, 24 bytes long.
a CDBException object at $0A7051F0, 24 bytes long
{104} normal block at 0x00FA9A68, 230 bytes long.
Data: < b j j > 14 62 85 00 6A 00 00 00 6A 00 00 00 01 00 00 00
{106} normal block at 0x00FA9790, 122 bytes long.
Data: < b 4 4 > 14 62 85 00 34 00 00 00 34 00 00 00 01 00 00 00
f:\rtm\vctools\vc7libs\ship\atlmfc\src\mfc\dbcore.cpp(55) : {80} client block at 0x00FA9630, subtype c0, 24 bytes long.
上面的内存地址内容是下面这些
...b..............O.D.B.C.;.D.B.Q.=.d.:.\.d.e.s.i
.g.n. .p.r.o.j.e.c.t.\.Z.c.y.D.e.s.i.g.n.\.Z.c.y.
D.e.s.i.g.n.\.m.a.i.n...m.d.b.;.D.r.i.v.e.r.=.{.M
.i.c.r.o.s.o.f.t. .A.c.c.e.s.s. .D.r.i.v.e.r. .(.
*...m.d.b.).}.;.D.r.i.v.e.r.I.d.=.2.5.;.F.I.L.=.M
.S. .A.c.c.e.s.s.;.M.a.x.B.u.f.f.e.r.S.i.z.e.=.2.
0.4.8.;.P.a.g.e.T.i.m.e.o.u.t.=.5.;..............
.b..4...4.......O.R.A.-.1.2.5.6.0.:. .T.N.S.:. .O
S....M.hV........q..R.z.^.v .S.Q.L.S.e.t.C.o.n.n.
e.c.t.A.t.t.r. .1Y%..........................."..
.....h...p...................p........b..\...`...
....D.r.i.v.e.r.=.{.M.i.c.r.o.s.o.f.t. .A.c.c.e.s
.s. .D.r.i.v.e.r. .(.*...m.d.b.).}.;.D.b.q.=.d.:.
\.d.e.s.i.g.n. .p.r.o.j.e.c.t.\.Z.c.y.D.e.s.i.g.n
.\.Z.c.y.D.e.s.i.g.n.\.m.a.i.n...m.d.b.;.........
.........................."......................
#2
就是说你要调用delete CDatabase对象指针,这样CDatabase类中的m_hdbc就会被释放掉。
#3
:)
问题解决了,和数据库没有关系,是我捕获的异常没有释放掉,对异常不熟呵呵!
e->Delete();
看来以后还是得好好看msdn,google也不是万能的啊
问题解决了,和数据库没有关系,是我捕获的异常没有释放掉,对异常不熟呵呵!
e->Delete();
看来以后还是得好好看msdn,google也不是万能的啊
#4
哈哈,正好需要
#1
程序在联网的时候数据从服务器上读取,并存一部分在本地服务器
断网时从本地服务器上读取,并且会经常执行查询服务器数据来判断网络是否连接上
现在联网时程序退出不会又内存泄露,但是断网情况下登录就有内存泄露
Detected memory leaks!
Dumping objects ->
{941} normal block at 0x0A7038A0, 230 bytes long.
Data: < b j j > 14 62 85 00 6A 00 00 00 6A 00 00 00 01 00 00 00
{943} normal block at 0x0A7035E8, 122 bytes long.
Data: < b 4 4 > 14 62 85 00 34 00 00 00 34 00 00 00 01 00 00 00
f:\rtm\vctools\vc7libs\ship\atlmfc\src\mfc\dbcore.cpp(55) : {917} client block at 0x0A7051F0, subtype c0, 24 bytes long.
a CDBException object at $0A7051F0, 24 bytes long
{104} normal block at 0x00FA9A68, 230 bytes long.
Data: < b j j > 14 62 85 00 6A 00 00 00 6A 00 00 00 01 00 00 00
{106} normal block at 0x00FA9790, 122 bytes long.
Data: < b 4 4 > 14 62 85 00 34 00 00 00 34 00 00 00 01 00 00 00
f:\rtm\vctools\vc7libs\ship\atlmfc\src\mfc\dbcore.cpp(55) : {80} client block at 0x00FA9630, subtype c0, 24 bytes long.
上面的内存地址内容是下面这些
...b..............O.D.B.C.;.D.B.Q.=.d.:.\.d.e.s.i
.g.n. .p.r.o.j.e.c.t.\.Z.c.y.D.e.s.i.g.n.\.Z.c.y.
D.e.s.i.g.n.\.m.a.i.n...m.d.b.;.D.r.i.v.e.r.=.{.M
.i.c.r.o.s.o.f.t. .A.c.c.e.s.s. .D.r.i.v.e.r. .(.
*...m.d.b.).}.;.D.r.i.v.e.r.I.d.=.2.5.;.F.I.L.=.M
.S. .A.c.c.e.s.s.;.M.a.x.B.u.f.f.e.r.S.i.z.e.=.2.
0.4.8.;.P.a.g.e.T.i.m.e.o.u.t.=.5.;..............
.b..4...4.......O.R.A.-.1.2.5.6.0.:. .T.N.S.:. .O
S....M.hV........q..R.z.^.v .S.Q.L.S.e.t.C.o.n.n.
e.c.t.A.t.t.r. .1Y%..........................."..
.....h...p...................p........b..\...`...
....D.r.i.v.e.r.=.{.M.i.c.r.o.s.o.f.t. .A.c.c.e.s
.s. .D.r.i.v.e.r. .(.*...m.d.b.).}.;.D.b.q.=.d.:.
\.d.e.s.i.g.n. .p.r.o.j.e.c.t.\.Z.c.y.D.e.s.i.g.n
.\.Z.c.y.D.e.s.i.g.n.\.m.a.i.n...m.d.b.;.........
.........................."......................
断网时从本地服务器上读取,并且会经常执行查询服务器数据来判断网络是否连接上
现在联网时程序退出不会又内存泄露,但是断网情况下登录就有内存泄露
Detected memory leaks!
Dumping objects ->
{941} normal block at 0x0A7038A0, 230 bytes long.
Data: < b j j > 14 62 85 00 6A 00 00 00 6A 00 00 00 01 00 00 00
{943} normal block at 0x0A7035E8, 122 bytes long.
Data: < b 4 4 > 14 62 85 00 34 00 00 00 34 00 00 00 01 00 00 00
f:\rtm\vctools\vc7libs\ship\atlmfc\src\mfc\dbcore.cpp(55) : {917} client block at 0x0A7051F0, subtype c0, 24 bytes long.
a CDBException object at $0A7051F0, 24 bytes long
{104} normal block at 0x00FA9A68, 230 bytes long.
Data: < b j j > 14 62 85 00 6A 00 00 00 6A 00 00 00 01 00 00 00
{106} normal block at 0x00FA9790, 122 bytes long.
Data: < b 4 4 > 14 62 85 00 34 00 00 00 34 00 00 00 01 00 00 00
f:\rtm\vctools\vc7libs\ship\atlmfc\src\mfc\dbcore.cpp(55) : {80} client block at 0x00FA9630, subtype c0, 24 bytes long.
上面的内存地址内容是下面这些
...b..............O.D.B.C.;.D.B.Q.=.d.:.\.d.e.s.i
.g.n. .p.r.o.j.e.c.t.\.Z.c.y.D.e.s.i.g.n.\.Z.c.y.
D.e.s.i.g.n.\.m.a.i.n...m.d.b.;.D.r.i.v.e.r.=.{.M
.i.c.r.o.s.o.f.t. .A.c.c.e.s.s. .D.r.i.v.e.r. .(.
*...m.d.b.).}.;.D.r.i.v.e.r.I.d.=.2.5.;.F.I.L.=.M
.S. .A.c.c.e.s.s.;.M.a.x.B.u.f.f.e.r.S.i.z.e.=.2.
0.4.8.;.P.a.g.e.T.i.m.e.o.u.t.=.5.;..............
.b..4...4.......O.R.A.-.1.2.5.6.0.:. .T.N.S.:. .O
S....M.hV........q..R.z.^.v .S.Q.L.S.e.t.C.o.n.n.
e.c.t.A.t.t.r. .1Y%..........................."..
.....h...p...................p........b..\...`...
....D.r.i.v.e.r.=.{.M.i.c.r.o.s.o.f.t. .A.c.c.e.s
.s. .D.r.i.v.e.r. .(.*...m.d.b.).}.;.D.b.q.=.d.:.
\.d.e.s.i.g.n. .p.r.o.j.e.c.t.\.Z.c.y.D.e.s.i.g.n
.\.Z.c.y.D.e.s.i.g.n.\.m.a.i.n...m.d.b.;.........
.........................."......................
#2
就是说你要调用delete CDatabase对象指针,这样CDatabase类中的m_hdbc就会被释放掉。
#3
:)
问题解决了,和数据库没有关系,是我捕获的异常没有释放掉,对异常不熟呵呵!
e->Delete();
看来以后还是得好好看msdn,google也不是万能的啊
问题解决了,和数据库没有关系,是我捕获的异常没有释放掉,对异常不熟呵呵!
e->Delete();
看来以后还是得好好看msdn,google也不是万能的啊
#4
哈哈,正好需要