.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Dispose.problem()

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
quigs
1210 Views, 7 Replies

Dispose.problem()

Hi there,
I have a disposal problem. When I check the "immediate window for any errors as my code is running, I get this error:
"Forgot to call Dispose? (Autodesk.AutoCAD.DatabaseServices.Line): DisposableWrapper"
I have also manually disposed of the line: LineDrag.Dispose()
But it has made no difference the message still comes up.
Any ideas,

Thanks in advance,

Martin.


Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD

Public Class BlankJig
Inherits DrawJig
Dim StPnt As Point3d ' Center - Start
Dim EndPt As New Point3d ' Center - End
Dim LineDrag As New Line ' Center = Line
Dim myPR As PromptPointResult ' Point Prompt
Function StartJig() As PromptPointResult
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim ppr1 As PromptPointResult = ed.GetPoint(vbLf & "Select Start point: ")
StPnt = ppr1.Value
LineDrag.StartPoint = StPnt
ppr1 = ed.Drag(Me)
Do
Select Case ppr1.Status
Case PromptStatus.OK
Return ppr1
Exit Do
End Select
Loop While ppr1.Status <> PromptStatus.Cancel
Return ppr1
End Function
Protected Overrides Function Sampler(ByVal prompts As JigPrompts) As SamplerStatus
myPR = prompts.AcquirePoint(vbLf & "Select End point:")
If myPR.Value.DistanceTo(EndPt) < 0.1 Then
Return SamplerStatus.NoChange
Else
EndPt = myPR.Value
LineDrag.EndPoint = EndPt
Return SamplerStatus.OK
End If
End Function
Protected Overrides Function WorldDraw(ByVal draw As GraphicsInterface.WorldDraw) As Boolean

LineDrag.ColorIndex = 4
draw.Geometry.Draw(LineDrag)

End Function

_
Public Sub DoJigA()
'Get the active document and begin a Transaction
Dim myDWG As Document = Application.DocumentManager.MdiActiveDocument
Using myTransMan As DatabaseServices.TransactionManager = myDWG.TransactionManager
Dim myTrans As Transaction = myTransMan.StartTransaction
'Open the BlockTable for Read
Dim myEd As Editor = myDWG.Editor
Dim myBT As BlockTable = myDWG.Database.BlockTableId.GetObject(DatabaseServices.OpenMode.ForRead)
Dim myBTR As BlockTableRecord = myBT(DatabaseServices.BlockTableRecord.ModelSpace).GetObject(DatabaseServices.OpenMode.ForWrite)
' Start Jig
Dim myJig As New BlankJig
Dim SelPt As Autodesk.AutoCAD.EditorInput.PromptPointResult
SelPt = myJig.StartJig()

LineDrag = myJig.LineDrag
myBTR.AppendEntity(LineDrag)
myTrans.AddNewlyCreatedDBObject(LineDrag, True)
myTrans.Commit()
LineDrag.Dispose()
End Using
LineDrag.Dispose()
End Sub
End Class
My name is Martin.. 😄
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: quigs

Is that really the code you're using, or not?

Your override of WorldDraw doesn't return a result.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6400123@discussion.autodesk.com...
Hi there,
I have a disposal problem. When I check the "immediate window for any errors as
my code is running, I get this error:
"Forgot to call Dispose? (Autodesk.AutoCAD.DatabaseServices.Line):
DisposableWrapper"
I have also manually disposed of the line: LineDrag.Dispose()
But it has made no difference the message still comes up.
Any ideas,

Thanks in advance,

Martin.


Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD

Public Class BlankJig
Inherits DrawJig
Dim StPnt As Point3d ' Center - Start
Dim EndPt As New Point3d ' Center - End
Dim LineDrag As New Line ' Center = Line
Dim myPR As PromptPointResult ' Point Prompt
Function StartJig() As PromptPointResult
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim ppr1 As PromptPointResult = ed.GetPoint(vbLf & "Select Start point:
")
StPnt = ppr1.Value
LineDrag.StartPoint = StPnt
ppr1 = ed.Drag(Me)
Do
Select Case ppr1.Status
Case PromptStatus.OK
Return ppr1
Exit Do
End Select
Loop While ppr1.Status <> PromptStatus.Cancel
Return ppr1
End Function
Protected Overrides Function Sampler(ByVal prompts As JigPrompts) As
SamplerStatus
myPR = prompts.AcquirePoint(vbLf & "Select End point:")
If myPR.Value.DistanceTo(EndPt) < 0.1 Then
Return SamplerStatus.NoChange
Else
EndPt = myPR.Value
LineDrag.EndPoint = EndPt
Return SamplerStatus.OK
End If
End Function
Protected Overrides Function WorldDraw(ByVal draw As
GraphicsInterface.WorldDraw) As Boolean

LineDrag.ColorIndex = 4
draw.Geometry.Draw(LineDrag)

End Function

_
Public Sub DoJigA()
'Get the active document and begin a Transaction
Dim myDWG As Document = Application.DocumentManager.MdiActiveDocument
Using myTransMan As DatabaseServices.TransactionManager =
myDWG.TransactionManager
Dim myTrans As Transaction = myTransMan.StartTransaction
'Open the BlockTable for Read
Dim myEd As Editor = myDWG.Editor
Dim myBT As BlockTable =
myDWG.Database.BlockTableId.GetObject(DatabaseServices.OpenMode.ForRead)
Dim myBTR As BlockTableRecord =
myBT(DatabaseServices.BlockTableRecord.ModelSpace).GetObject(DatabaseServices.OpenMode.ForWrite)
' Start Jig
Dim myJig As New BlankJig
Dim SelPt As Autodesk.AutoCAD.EditorInput.PromptPointResult
SelPt = myJig.StartJig()

LineDrag = myJig.LineDrag
myBTR.AppendEntity(LineDrag)
myTrans.AddNewlyCreatedDBObject(LineDrag, True)
myTrans.Commit()
LineDrag.Dispose()
End Using
LineDrag.Dispose()
End Sub
End Class
Message 3 of 8
quigs
in reply to: quigs

Thanks for the reply Tony,
but I am a beginner, and your response isn't clear to
me. Could you maybe elaborate a little what you mean?
Sorry that I don't understand.

Thanks again.

Martin. Edited by: quigs on May 31, 2010 8:58 AM
My name is Martin.. 😄
Message 4 of 8
quigs
in reply to: quigs

I fixed it,
no worries,

Cheers any way 😄
My name is Martin.. 😄
Message 5 of 8
quigs
in reply to: quigs

Hi all, A few weeks ago I asked the original question in this group about disposing of objects. Well, with a bit of research I found the answer myself. I was using the code straight out of Jerry Winters book to learn how to programme, probably like quiet a lot of you here, and I also used his jig examples. Well if you did use this material, then like me, if your still a n00b you may have ran into the same problems of disposal, or, you may not even be aware of what that is and wonder why you routine stalls for several seconds when you finish running your jig heavy routine in cad. To cut to the chase the very question I asked for help on is answered In the dev cast by Fenton Webb. The link is posted below, and you have to scroll down.

 

here

 

Cheers, and hope it helps some people. Martin.

My name is Martin.. 😄
Message 6 of 8
StormyC
in reply to: quigs

Hey Martin

 

Getting the same issue but cannot locate the dev cast you refer to.. Can temm me which dev cast your refering to and maybe a direct link....

 

Many thanks!

Message 7 of 8
quigs
in reply to: StormyC

Hi StormyC,

Basically, you need to dispose of objects like lines, arcs, circles, block

references & new Layers once you have finished with them:

 

For example:  If you have a line:

Dim  NewLine as line = new line(P1, P2)

 

At the end of you function dispose it like this:

NewLine.dispose()

 

That will stop your machine or routines from crashing.

As a rule, anything committed to the database, or that could be committed, even

lines and such you don’t actually use, need to be disposed of.  I hope that’s clear.

 

And really sorry, but I checked my link I put in & it’s moved, hope that helps anyway.

 

 

Martin.

My name is Martin.. 😄
Message 8 of 8
StormyC
in reply to: quigs

Thanks for the reply...

 

Sorted the problem now, I needed to dispose of the individual objects within a dbojectcollection ......

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost